JSONKit的使用方法
来源:互联网 发布:砧板 知乎 编辑:程序博客网 时间:2024/06/02 21:19
json开源的类库有很多,其中JSONKit库是非常简单易用而且效率又比较高的,重要的JSONKit适用于ios 5.0以下的版本使用.
JSONKit库来解析json文件,只需要下载JSONKit.h 和JSONKit.m添加到工程中;然后加入libz.dylib#import "JSONKit.h"
//假设 strJson 是网络上接收到的 json 字符串,
NSString *strJson = @"[{\"Id\": 1,\"BrandName\": \"爱马仕\" },{\"Id\": 2,\"BrandName\": \"安娜苏\"}]";
NSArray *arrlist=[strJson objectFromJSONString];
NSLog(@"%d",[arrlist count]);
for (int i=0; i<[arrlist count]; i++) {
NSDictionary *item=[arrlist objectAtIndex:i];
NSString *BrandName=[item objectForKey:@"BrandName"];
NSLog(@"%@",BrandName);
}
字典arrlist便是解析好的json文件了。
JSONKit库也可以用来生成json文件
NSMutableDictionary *jsonDic = [NSMutableDictionary dictionary];NSMutableDictionary *alert = [NSMutableDictionary dictionary]
;NSMutableDictionary *aps = [NSMutableDictionary dictionary];
[alert setObject:@"a msg come!" forKey:@"body"];
[aps setObject:alert forKey:@"alert"];
[aps setObject:@"3" forKey:@"bage" ];
[aps setObject:@"def.mp3" forKey:@"sound"];
[jsonDic setObject:aps forKey:@"aps"];
NSString *strJson = [jsonDic JSONString];
0 0
- JSONKit的使用方法
- JSONKit的使用方法
- JSONKit的使用方法
- JSONKit的使用方法
- JSONKit的使用方法
- JSONKit使用方法
- JsonKit使用方法
- JsonKit使用方法
- JSonKit 的使用
- JSONKit的使用
- 关于JSONKit的使用
- JSONKit 的几个错误
- jsonKit的解决办法
- JsonKit的基本使用
- JSONKit
- jsonkit
- JSONKIT isa错误的解决办法
- JSONKIT isa错误的解决办法
- C++赋值运算符重载
- freemarker四种变量
- cas client入门之三:单点登出
- [LeetCode24]Swap Nodes in Pairs
- Activty之我见(处女帖,跪求各位大婶留下脚板印)
- JSONKit的使用方法
- python--批量创建文件夹
- Jump的计划
- [ZOJ 3633]Alice's present 离线分块/线段树
- cookie与session解释
- MFC中CString与Char类型字符串的相互转换
- 开发日记_2014.6.11
- html title小图标
- 【黑马程序员】java基础_泛型