I'm still trying (I already asked a few question about this) to parse my own JSON file. Here is my JSON :
{
"album":[
{
"album_titre":"Publicité",
"album_photo":"blabla.jpg",
"album_videos":[
{
"titre_video":"Chauffage Compris",
"duree_video":"01'25''",
"photo_video":"chauffage.jpg",
"lien_video":"www.bkjas.jhas.kajs"
},
{
"titre_video":"NIFFF 2012",
"duree_video":"01'43''",
"photo_video":"nifff.jpg",
"lien_video":"www.bkjas.jhas.kajs"
}
]
},
{
"album_titre":"Events",
"album_photo":"bloublou.jpg",
"album_videos":[
{
"titre_video":"Auvernier Jazz",
"duree_video":"01'15''",
"photo_video":"auvernier.jpg",
"lien_video":"www.bkjas.jhas.kajs"
},
{
"titre_video":"NIFFF 2011",
"duree_video":"01'03''",
"photo_video":"nifff2011.jpg",
"lien_video":"www.bkjas.jhas.kajs"
}
]
}
]
}
With help of community, I've made this :
- (void) viewDidLoad
{
[super viewDidLoad];
dispatch_async (kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL:lienAlbumsVideo];
[self performSelectorOnMainThread:@selector(fetchedData:)withObject:data waitUntilDone:YES];
});
}
- (void)fetchedData:(NSData *)responseData {
NSError* error;
NSDictionary *document = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
if (document==nil)
{
NSLog( @"oops\n%@", error);
}
NSArray *album = document[@"album"];
NSMutableArray *album_titre = [NSMutableArray new];
NSMutableArray *album_photo = [NSMutableArray new];
NSMutableArray *album_videos = [NSMutableArray new];
for( NSDictionary *elementOnRoot in album )
{
[album_titre addObject:elementOnRoot[@"album_titre"]];
[album_photo addObject:elementOnRoot[@"album_photo"]];
[album_videos addObject:elementOnRoot[@"album_videos"]];
}
NSLog(@"%@", [album_titre objectAtIndex:0]);
NSLog(@"%@", [album_videos objectAtIndex:1]);
NSLog(@"%@", album_photo);
}
Now, I'm a bit mixed up with structure. My question is how (using my actual Xcode) can I have a list (NSArray or dictionary) of "titre_video", "duree_video", "photo_video" and "lien_video"?
Thank you for your help and sorry for my basic xcode level...
Nicolas
for( NSDictionary *albumDic in album )
{
for( NSDictionary *album_videosDic in albumDic[@"album_videos"])
{
[album_titre addObject:album_videosDic[@"titre_video"]];
[album_videos addObject:album_videosDic[@"duree_video"]];
[album_photo addObject:album_videosDic[@"photo_video"]];
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.