我用的Json例子如下(网络上很多人都用这个例子):
{
"生命基金会" : {
"dabei88" : {
"digits" : 22,
"name" : "大悲出相图",
"length" : 88
}
},
"华藏净宗学会" : {
"zhaomu" : {
"digits" : 3,
"name" : "净宗朝暮课本",
"length" : 142
},
"kesong" : {
"digits" : 2,
"name" : "净宗共修课本",
"length" : 75
}
}
}
}
(一)首先自己写一个函数,用来生成Json,如下:
- (NSDictionary *)dictionaryByCustom{
NSMutableDictionary *mutableDict=[NSMutableDictionary dictionary];
NSMutableDictionary *sub1Dict=[NSMutableDictionary dictionary];
NSMutableDictionary *sub2Dict=[NSMutableDictionary dictionary];
sub2Dict=[NSMutableDictionary dictionaryWithObjectsAnd Keys:@"净宗朝暮课本",@"name",[NSNumber numberWithInteger:142],@"length",[NSNumber numberWithInteger:3],@"digits",nil];
[sub1Dict setValue:sub2Dict forKey:@"zhaomu"];
sub2Dict=[NSMutableDictionary dictionary];//重新分配
sub2Dict=[NSMutableDictionary dictionaryWithObjectsAnd Keys:@"净宗共修课本",@"name",[NSNumber numberWithInteger:75],@"length",[NSNumber numberWithInteger:2],@"digits",nil];
[sub1Dict setValue:sub2Dict forKey:@"kesong"];
[mutableDict setValue:sub1Dict forKey:@"华藏净宗学会"];
sub1Dict=[NSMutableDictionary dictionary];//重新分配
sub2Dict=[NSMutableDictionary dictionary];//重新分配
sub2Dict=[NSMutableDictionary dictionaryWithObjectsAnd Keys:@"大悲出相图",@"name",[NSNumber numberWithInteger:88],@"length",[NSNumber numberWithInteger:22],@"digits",nil];
[sub1Dict setValue:sub2Dict forKey:@"dabei88"];
[mutableDict setValue:sub1Dict forKey:@"生命基金会"];
return mutableDict;
}
(二)将Json存进本地文件夹(下面代码在你需要用到的地方写):
}
(二)将Json存进本地文件夹(下面代码在你需要用到的地方写):