objective c - iOS JSON Parsing, array with multiple array -
i have json array multiple object , don't know how grab "url" tag nsarray or nsdictionary , show image url in tableview. can't change json data format.how should this?
here json response looks like:
{ "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", "title": "dal swaraj yatra" }, { "url": "/media/images/cbvv_smxiaalqp8.original.jpg", "title": "dal swaraj yatra" }, { "url": "/media/images/cahec--ukaarc_z.original.jpg", "title": "dal swaraj yatra" } ] ] }, { "id": 2530, "meta": { "type": "dashboard.newsevents", "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, "meta": { "type": "dashboard.newsevents", "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", "title": "holi in barsana" }, { "url": "/media/images/holi.._.original.jpg", "title": "holi in barsana" }, { "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" } ] ] },
i'm using code "url" array. plz correct me ?
nsarray *imageurlarray = [[self.jsondata objectatindex:indexpath.row]objectforkey:@"cover_url"]; nslog(@"image url array:%@",imageurlarray); nsstring *imageurl = [imageurlarray valueforkey:@"url"]; nslog(@"image url:%@",imageurl);
to view json structure - http://jsonviewer.stack.hu/
nsmutablearray* imageurlarray = [nsmutablearray new]; nsarray* jsonarray = jsondata[@"pages"]; (int = 0; i<[jsonarray count]; i++) { nsarray* coverurlarray = jsonarray[i][@"cover_url"]; (int t = 0; t< [coverurlarray count]; t++) { nsarray* urlarray = coverurlarray[t]; (int x = 0; x<[urlarray count]; x++) { [imageurlarray addobject:urlarray[x][@"url"]]; } } } nslog(@"imageurlarray: %@", imageurlarray); //imageurlarray contains url //in cell row @ indexpath --> use imageurlarray[indexpath.row];
Comments
Post a Comment