【问题标题】:How to read a JSON file using the NSJSONSerialization Class Reference?如何使用 NSJSONSerialization 类参考读取 JSON 文件?
【发布时间】:2012-05-14 11:05:10
【问题描述】:

我需要使用 NSJSONSerialization 类参考来读取 JSON 文件,我发现的所有关于使用此类的示例都是从网页本身读取内容,而不是从之前创建的 JSON 文件中读取.任何人都知道如何使用该类从 JSON 文件中解析?谢谢。

【问题讨论】:

    标签: json ios5


    【解决方案1】:

    简单,快速的'n'dirty示例:

    NSString *jsonPath = [[NSBundle mainBundle] pathForResource:@"foobar"
                                                         ofType:@"json"];
    NSData *data = [NSData dataWithContentsOfFile:jsonPath];
    NSError *error = nil;
    id json = [NSJSONSerialization JSONObjectWithData:data
                                              options:kNilOptions
                                                error:&error];
    NSLog(@"JSON: %@", json);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-21
      • 2017-12-23
      • 1970-01-01
      • 2022-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多