保存一下iOS 读取Json的代码,留着以后Copy用,哈哈。

 

    NSString* path = [[NSBundle mainBundle] pathForResource: @"Sandwiches"
                                                     ofType: @"json"];
    NSString* data = [NSString stringWithContentsOfFile: path
                                               encoding: NSUTF8StringEncoding
                                                  error: nil];
    
    NSData* resultData = [data dataUsingEncoding:NSUTF8StringEncoding];
    _sandwiches = [NSJSONSerialization JSONObjectWithData:resultData
                                                       options:kNilOptions
                                                         error:nil];

 

json文件,或者从网络读取的json,如图iOS 读取Json 代码

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-06
  • 2022-01-23
  • 2021-12-01
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
猜你喜欢
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2022-01-01
  • 2021-10-28
相关资源
相似解决方案