JSONKit的使用PS.勿使用SBJson

JSONKit库是非常简单易用而且效率又比较高。

下载地址: https://github.com/johnezang/JSONKit

使用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(%@ 
   
 

字典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:3bage" ];
[aps setobject:def.mp3sound"];
[jsonDic setobject:aps forKey:aps"];
Nsstring *strjson = [jsonDic JSONString];

相关文章

AJAX是一种基于JavaScript和XML的技术,能够使网页实现异步交...
在网页开发中,我们常常需要通过Ajax从后端获取数据并在页面...
在前端开发中,经常需要循环JSON对象数组进行数据操作。使用...
AJAX(Asynchronous JavaScript and XML)是一种用于创建 We...
AJAX技术被广泛应用于现代Web开发,它可以在无需重新加载页面...
Ajax是一种通过JavaScript和HTTP请求交互的技术,可以实现无...