IOS simple local json format file parsing examples
document
{ "data":[{ "name" : "", "content" : "", "images" :[ { "imageurl" : "/2017/0702/" }, { "imageurl" : "/onevcat/Kingfisher/master/images/" }, { "imageurl" : "/2015/0121/" } ] }, { "name" : "", "content" : "", "images" :[ { "imageurl" : "/2017/0702/" }, { "imageurl" : "/2017/0702/" }, { "imageurl" : "/2017/0702/" } ] }, { "name" : "", "content" : "", "images" :[ { "imageurl" : "/2017/0702/" }, { "imageurl" : "/2017/0703/" }, { "imageurl" : "/2017/0702/" } ] } ] }
Analysis
NSError *error; NSString *_ljPath = [[NSBundle mainBundle]pathForResource:@"ljweibo" ofType:@"json"]; NSDictionary *_ljDic = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:_ljPath] options:NSJSONReadingMutableLeaves error:&error]; //ArrayNSArray *_ljAllArray = [_ljDic objectForKey:@"data"]; for (NSInteger a = 0; a < _ljAllArray.count; a++) { ljWeiboInfo *_info = [[ljWeiboInfo alloc]init]; _info.ljContentStr = [_ljAllArray[a] objectForKey:@"content"]; NSArray *_ljArraylj = [_ljAllArray[a] objectForKey:@"images"]; //Get all pictures NSMutableArray *_ljMuArray = [[NSMutableArray alloc]init]; for (NSInteger i = 0; i < _ljArraylj.count; i++) { [_ljMuArray addObject:[_ljArraylj[i] objectForKey:@"imageurl"]]; } _info.ljImageUrlArray = _ljMuArray; [ addObject:_info]; }
If you have any questions, please leave a message or go to the community of this site to exchange and discuss. Thank you for reading. I hope it can help you. Thank you for your support for this site!