美文网首页
OC 读取本地JSON

OC 读取本地JSON

作者: osnail | 来源:发表于2019-08-28 10:41 被阅读0次
// 读取本地JSON文件
- (NSDictionary *)readLocalFileWithName:(NSString *)name {
  // 获取文件路径
  NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"json"];
  // 将文件数据化
  NSData *data = [[NSData alloc] initWithContentsOfFile:path];
  // 对数据进行JSON格式化并返回字典形式
  return [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
}

相关文章

网友评论

      本文标题:OC 读取本地JSON

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