// Created by lyz on 15-8-28.
// Copyright (c) 2015年 mac. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface DateJosn : NSObject
+ (id)dateWithJosn:(NSString *)filejosnName;
@end
// Created by lyz on 15-8-28.
// Copyright (c) 2015年 mac. All rights reserved.
//
#import "DateJosn.h"
@implementation DateJosn
+ (id)dateWithJosn:(NSString *)filejosnName{
NSString *jsonPath = [[NSBundle mainBundle] pathForResource:filejosnName ofType:nil];
NSData *data = [NSData dataWithContentsOfFile:jsonPath];
//iOS5之前,解析JSON文件JsonKit、SBJSON、TouchJson
//iOS5之后使用NSJSONSerialization
/*
NSJSoNReadingMutableContainers
NSJSONReadingMuTableLeaves
NSJSONReadingMutableContainers 解析后的数据最外层是数组或者字典
NSJSONReadingMutableLeaves 解析后的数据最外层是字符串
NSJSONReadingAllowFragments 解析后的数据最外层不是数组和者字典
*///NSJSONSerializatio
id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
return result;//第一层数据 第一层数据
}
@end
外界使用时,只需眼转入json文件名
NSDictionary *dic = [DateJosn dateWithJosn:US_BOX];//US_BOX JSON文件名的宏定义