您的位置:首页 > 移动开发 > IOS开发

【代码笔记】iOS-json文件的两种解析方式

2017-12-05 08:59 357 查看
一,工程图。



二,代码。

#import "ViewController.h"
#import "SBJson.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

//第一种JSON解析方式,系统自带的JSON解析方式
NSString * datapath = [[NSBundle mainBundle] pathForResource:@"failureReason" ofType:@"json"];
NSData * jsonData = [NSData dataWithContentsOfFile:datapath];
NSMutableDictionary *arrayDic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
NSLog(@"----arrayDic---%@",arrayDic);

//SBJson解析
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"failureReason" ofType:@"json"];
NSString *myJSON = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];
NSDictionary *json = [myJSON JSONValue];

NSLog(@"--json--%@",json);

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: