iOS JSON解析,包含多个数组的数组

iOS JSON解析,包含多个数组的数组,第1张

概述我有一个带有多个对象的 JSON数组,我不知道如何将“url”标记作为NSArray或NSDictionary来获取并在Tableview中显示该图像URL.我无法更改JSON数据格式.我该怎么做? 以下是JSON响应的样子: {"meta": { "total_count": 10},"pages": [ { "id": 7, "meta": 我有一个带有多个对象的 JSON数组,我不知道如何将“url”标记作为NSArray或NSDictionary来获取并在tablevIEw中显示该图像URL.我无法更改JsON数据格式.我该怎么做?

以下是JsON响应的样子:

{"Meta": {    "total_count": 10},"pages": [    {        "ID": 7,"Meta": {            "type": "dashboard.NewsEvents","detail_url": "http://suno.to/API/v1/pages/7/"        },"Title": "NoEvent","created_at": "2016-03-06T10:42:19.646000Z","cover_url": [            [                {                    "url": "/media/images/Maha_Shivratri2.original.jpg","Title": "Maha Shivratri2.jpg"                },{                    "url": "/media/images/Maha_Shivratri1.original.jpg","Title": "Maha Shivratri1.jpg"                }            ],[                {                    "url": "/media/images/Celebrations.original.jpg","Title": "Celebrations.jpg"                },{                    "url": "/media/images/Crew.original.jpg","Title": "Crew.jpg"                },{                    "url": "/media/images/World_record.original.jpg","Title": "World record.jpg"                },{                    "url": "/media/images/AI_pilots.original.jpg","Title": "AI pilots.jpg"                }            ],[                {                    "url": "/media/images/CbVv-VbWEAAmwv_.original.jpg","Title": "DAL SWaraJ YATRA"                },{                    "url": "/media/images/CbVv_-TWwAE7RjM.original.jpg",{                    "url": "/media/images/CbVv_SmXIAALQP8.original.jpg",{                    "url": "/media/images/CahEc--UkAArc_z.original.jpg","Title": "DAL SWaraJ YATRA"                }            ]        ]    },{        "ID": 2530,"detail_url": "http://suno.to/API/v1/pages/2530/"        },"Title": "World Culture Festival","created_at": "2016-03-12T06:59:21.023000Z","cover_url": [            [                {                    "url": "/media/images/Security.original.jpg","Title": "Security check"                }            ],[                {                    "url": "/media/images/Elephant_statues.original.jpg","Title": "Elephant"                }            ],[                {                    "url": "/media/images/6.original.jpg","Title": "Stage"                },{                    "url": "/media/images/4.original.jpg","Title": "Stage"                }            ]        ]    },{        "ID": 2675,"detail_url": "http://suno.to/API/v1/pages/2675/"        },"Title": "Holi in barsana","created_at": "2016-03-17T12:35:09.308000Z","cover_url": [            [                {                    "url": "/media/images/Brajwasi_playing_holi_.original.jpg","Title": "Holi in barsana"                },{                    "url": "/media/images/dancing_.original.jpg",{                    "url": "/media/images/holi.._.original.jpg",{                    "url": "/media/images/holi..._.original.jpg","Title": "Holi in barsana"                }            ],[                {                    "url": "/media/images/Lathmar_holi_19_n54f7LJ.original.jpg","Title": "Lathmar Holi in barsana"                }            ],[                {                    "url": "/media/images/Lathmar_holi_17.original.jpg","Title": "Lathmar Holi in barsana"                },{                    "url": "/media/images/Lathmar_holi_20.original.jpg","Title": "Lathmar Holi in barsana"                }            ]        ]    },

我正在使用此代码来获取“url”数组. Plz纠正我?

NSArray *imageUrlArray = [[self.JsonData    objectAtIndex:indexPath.row]objectForKey:@"cover_url"];  NSLog(@"IMAGE URL ARRAY:%@",imageUrlArray);  Nsstring *imageUrl = [imageUrlArray valueForKey:@"url"];  NSLog(@"IMAGE URL:%@",imageUrl);
解决方法 查看JsON结构 – http://jsonviewer.stack.hu/

NSMutableArray* imageurlArray = [NSMutableArray new];NSArray* JsonArray = JsonData[@"pages"];for (int i = 0; i<[JsonArray count]; i++) {    NSArray* coverUrlArray = JsonArray[i][@"cover_url"];    for (int t = 0; t< [coverUrlArray count]; t++) {        NSArray* UrlArray = coverUrlArray[t];        for (int x = 0; x<[UrlArray count]; x++) {            [imageurlArray addobject:UrlArray[x][@"url"]];        }    }}NSLog(@"imageurlArray: %@",imageurlArray);//imageurlArray contains all url//In cell for row at indexpath --> use imageurlArray[indexPath.row];
总结

以上是内存溢出为你收集整理的iOS JSON解析,包含多个数组的数组全部内容,希望文章能够帮你解决iOS JSON解析,包含多个数组的数组所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1029771.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存