IOS

关注公众号 jb51net

关闭
首页 > 软件编程 > IOS > IOS json

IOS 简单的本地json格式文件解析的实例详解

作者:水桶前辈

这篇文章主要介绍了IOS 简单的本地json格式文件解析的实例详解的相关资料,希望通过本文大家能够掌握这部分内容,需要的朋友可以参考下

IOS 简单的本地json格式文件解析的实例详解

ljweibo.json文件

{ 
  "data":[{ 
   
      "name"  : "", 
      "content" : "", 
      "images" :[ 
            { 
            "imageurl" : "http://image.nationalgeographic.com.cn/2017/0702/20170702124619643.jpg" 
            }, 
            { 
            "imageurl" : "https://raw.githubusercontent.com/onevcat/Kingfisher/master/images/kingfisher-2.jpg" 
            }, 
            { 
            "imageurl" : "http://image.nationalgeographic.com.cn/2015/0121/20150121033625957.jpg" 
            } 
           ] 
  }, 
  { 
      "name"  : "", 
      "content" : "", 
      "images" :[ 
            { 
            "imageurl" : "http://image.nationalgeographic.com.cn/2017/0702/20170702124619643.jpg" 
            }, 
            { 
            "imageurl" : "http://image.nationalgeographic.com.cn/2017/0702/20170702124619643.jpg" 
            }, 
            { 
            "imageurl" : "http://image.nationalgeographic.com.cn/2017/0702/20170702124619643.jpg" 
            } 
            ] 
  }, 
  { 
      "name"  : "", 
      "content" : "", 
      "images" :[ 
            { 
            "imageurl" : "http://image.nationalgeographic.com.cn/2017/0702/20170702124619643.jpg" 
            }, 
            { 
            "imageurl" : "http://image.nationalgeographic.com.cn/2017/0703/20170703042329843.jpg" 
            }, 
            { 
            "imageurl" : "http://image.nationalgeographic.com.cn/2017/0702/20170702124619643.jpg" 
            } 
            ] 
   } 
  ] 
} 

解析

NSError *error; 
NSString *_ljPath = [[NSBundle mainBundle]pathForResource:@"ljweibo" ofType:@"json"]; 
NSDictionary *_ljDic = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:_ljPath] options:NSJSONReadingMutableLeaves error:&error]; 
//数组 
NSArray *_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"]; 
  //获取全部的图片 
  NSMutableArray *_ljMuArray = [[NSMutableArray alloc]init]; 
  for (NSInteger i = 0; i < _ljArraylj.count; i++) { 
    [_ljMuArray addObject:[_ljArraylj[i] objectForKey:@"imageurl"]]; 
  } 
  _info.ljImageUrlArray = _ljMuArray; 
   
  [self.ljArray addObject:_info]; 
} 

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

您可能感兴趣的文章:
阅读全文