ios 简单的本地json格式文件解析

来源:互联网 发布:七爷交友平台知乎 编辑:程序博客网 时间:2024/06/07 06:40

ljweibo.json文件

{    "data":[{                "name"    : "孙悟空",            "content" : "7月12日的国务院常务会议上,李克强明确要求,要将已审议的《快递条例(草案)》向社会公开征求意见。在会上,总理说了这么一段话:“几年前,快递业刚刚开始发展的时候,有些城市不允许快递存在,理由是影响市容整洁,快递员骑的摩的也不允许停放。但是我们认为,对于任何新生事物,应尽量秉持‘包容审慎’的监管方式,不能一上来就‘管死,有些城市不允许快递存在,理由是影响市容整洁,快递员骑的摩的也不允许停放。但是我们认为,对于任何新生事物,应尽量秉持‘包容审慎’的监管方式,不能一上来就‘管死",            "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" : "7月12日的国务院常务会议上,李克强明确要求,要将已审议的《快递条例(草案)》向社会公开征求意见。在会上,总理说了这么一段话:“几年前,快递业刚刚开始发展的时候,有些城市不允许快递存在,理由是影响市容整洁,快递员骑的摩的也不允许停放。但是我们认为,对于任何新生事物,应尽量秉持‘包容审慎’的监管方式,不能一上来就‘管死,有些城市不允许快递存在,理由是影响市容整洁,快递员骑的摩的也不允许停放。但是我们认为,对于任何新生事物,应尽量秉持‘包容审慎’的监管方式,不能一上来就‘管死",            "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" : "7月12日的国务院常务会议上,李克强明确要求,要将已审议的《快递条例(草案)》向社",            "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];          }


原创粉丝点击