iOS 读取Json 代码

时间:2014-09-19 17:28:25   收藏:0   阅读:190

保存一下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,如图bubuko.com,布布扣

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!