读取JSON文件

2016-07-28  本文已影响58人  走道牙的人

经测试 MJExtension 并不能读取本地.json格式的文件,需使用oc自带方法

// 经测试该方法无用
NSArray *array1 = [DBDistrict mj_objectArrayWithFilename:@"ttt.json"];

// 需使用以下方法
NSString *path = [[NSBundle mainBundle] pathForResource:@"ttt" ofType:@"json"];

NSData *jsonData = [NSData dataWithContentsOfFile:path options:NSDataReadingMappedIfSafe error:nil];

NSArray *array = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
上一篇 下一篇

猜你喜欢

热点阅读