jsonkit 库 for cocoa

cocoa 下json开源的类库有很多。。jsonkit是其中一个,它使 用简单,只有两个文件 只要拷到工程里就可以用了。

下面的得单的使 用例子:

//比如 strJson 是网络上接收到的 json 字符串,

 #import "JSONKit.h"

NSString *strJson = @"{\"aps\": {\"alert\":{\"body\":\"a msg come!\"},\"bage\":3,\"sound\":\"def.mp3\"}}";
NSDictionary *result = [jsonData  objectFromJSONData]; 

 

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];



posted on 2011-12-09 15:09  110440  阅读(2447)  评论(0编辑  收藏  举报

导航