美文网首页
读取JSON文件

读取JSON文件

作者: 走道牙的人 | 来源:发表于2016-07-28 09:15 被阅读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];

相关文章

网友评论

      本文标题:读取JSON文件

      本文链接:https://www.haomeiwen.com/subject/otkajttx.html