您的位置:首页 > Web前端 > JavaScript

JSON_JSONKit_ 解析本地文件

2015-09-28 17:36 666 查看
需要从gitHub上下载JSONKit文件。也可以从我上传的资料上下载即可。

//1.获取文件路径

NSString *path = [[NSBundle
mainBundle]pathForResource:@"JSON_StudentInfo"
ofType:@"txt"];

//2.创建data对象

NSData *data = [[NSData
alloc]initWithContentsOfFile:path];

//3.解析

NSArray *array = [data
objectFromJSONData];

//4.组装

_array =[[NSMutableArray
alloc]initWithCapacity:6];

for (NSDictionary *dict
in array) {

Student *student = [Student
new];

[student setValuesForKeysWithDictionary:dict];
[_array
addObject:student];
}

//5.校验

for (Student *student
in _array) {

NSLog(@"%@",student);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: