![【代码笔记】iOS-json文件的两种解析方式 【代码笔记】iOS-json文件的两种解析方式](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
一,工程图。
二,代码。
![【代码笔记】iOS-json文件的两种解析方式 【代码笔记】iOS-json文件的两种解析方式](https://image.shishitao.com:8440/aHR0cHM6Ly9jb21tb24uY25ibG9ncy5jb20vaW1hZ2VzL2NvcHljb2RlLmdpZg%3D%3D.gif?w=700&webp=1)
#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); }
![【代码笔记】iOS-json文件的两种解析方式 【代码笔记】iOS-json文件的两种解析方式](https://image.shishitao.com:8440/aHR0cHM6Ly9jb21tb24uY25ibG9ncy5jb20vaW1hZ2VzL2NvcHljb2RlLmdpZg%3D%3D.gif?w=700&webp=1)