场景:往xcode工程中添加一个data.json 资源,如果想在项目中获取此资源的话就可以使用一下代码:
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"json"];
NSString *jsonStr = [NSString stringWithContentsOfFile:filepath encoding:NSUTF8StringEncoding error:nil ];
NSData *data = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *tempDictQueryDiamond = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
网友评论