• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - AFNetworking 获取 json 值并将其保存为 NSMutablearray

[复制链接]
菜鸟教程小白 发表于 2022-12-13 08:44:49 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我是 ios 及其开发的新手。我有正确设置的干净代码 AFNetworking。我的基本 URl 的 json Encording 有 JSON 对象和数组以及值。在我的 JSON 输出中,我想在每次获取 Null 时获取“缩略图”的值。请帮助我获取我的 json 输出的“名称、缩略图、id、图像”。请找到我的 NSDictionary 类型打印对象的 NSlog。

2014-07-20 09:08:33.110 WADTourisum[1157:60b] Reachability Flag Status: -R ------- networkStatusForFlags
2014-07-20 09:08:33.879 WADTourisum[1157:60b] JSON: {
    Main =     (
                {
            id = 1;
            "image_bundle_id" = 1;
            images =             (
                "http://wearedesigners.net/clients/clients12/tourism/images/guides/oceans/slide_images/1.jpg",
                "http://wearedesigners.net/clients/clients12/tourism/images/guides/oceans/slide_images/2.jpg",
                "http://wearedesigners.net/clients/clients12/tourism/images/guides/oceans/slide_images/3.jpg"
            );
            name = OCEAN;
            thumbnail = "http://wearedesigners.net/clients/clients12/tourism/images/guides/thumbs/ocean.jpg";
        },
                {
            id = 2;
            "image_bundle_id" = 23;
            images =             (
                "http://wearedesigners.net/clients/clients12/tourism/images/guides/heritages/slide_images/1.jpg",
                "http://wearedesigners.net/clients/clients12/tourism/images/guides/heritages/slide_images/2.jpg",
                "http://wearedesigners.net/clients/clients12/tourism/images/guides/heritages/slide_images/3.png"
            );
            name = Heritage;
            thumbnail = "http://wearedesigners.net/clients/clients12/tourism/images/guides/thumbs/heritage.jpg";
        },
                {
            id = 3;
            "image_bundle_id" = 0;
            images =             (
            );
            name = "Tea Country";
            thumbnail = "http://wearedesigners.net/clients/clients12/tourism/images/guides/thumbs/teaCountry.jpg";
        },
                {
            id = 4;
            "image_bundle_id" = 0;
            images =             (
            );
            name = "WILD LIFE";
            thumbnail = "http://wearedesigners.net/clients/clients12/tourism/images/guides/thumbs/wildLife.jpg";
        },
                {
            id = 5;
            "image_bundle_id" = 0;
            images =             (
            );
            name = Culture;
            thumbnail = "http://wearedesigners.net/clients/clients12/tourism/images/guides/thumbs/culture.jpg";
        },
                {
            id = 6;
            "image_bundle_id" = 0;
            images =             (
            );
            name = "NIGHT LIFE";
            thumbnail = "http://wearedesigners.net/clients/clients12/tourism/images/guides/thumbs/nightLife.jpg";
        }
    );

}

我的代码片段

-(void) retriveData
{



    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    [manager GET"http://www.fr20.wearedesigners.net/WADMac/tourism/fetchGuideListAndroid.php"
     parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

         self.posts =(NSDictionary *)responseObject;
         self.post =self.posts[@"thumbnail"];




        NSLog(@"JSON: %@", self.post);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle"lease log into internetet"
                                                            message:[error localizedDescription]
                                                           delegate:nil
                                                  cancelButtonTitle"Ok"
                                                  otherButtonTitles:nil];
        [alertView show];
    }];







}



Best Answer-推荐答案


您收到了响应,我看到的唯一问题是您无法正确检索值。

在从 JSON 中获取数据时,请记住获取数据的格式,即获取数组或字典。

看到您的回复,您将获得本身包含字典的 Array。

使用以下代码获取值

NSArray *array = [responseObject valueForKey"Main"];

    for (NSDictionary *dict in array) {
        NSInteger ids = [[dict valueForKey"id"] integerValue];
        NSString *name = [dict valueForKey"name"];
        NSString *thumbnail = [dict valueForKey"thumbnail"];
        NSArray *arrImages = [dict valueForKey"images"];
        //You can use them accordingly

    } 

希望这对您有所帮助。快乐编码

关于ios - AFNetworking 获取 json 值并将其保存为 NSMutablearray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24850911/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap