JSONKit用法

来源:互联网 发布:福士苍汰 知乎 编辑:程序博客网 时间:2024/05/22 12:08

使用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];//从strJson 将数组解析出来    NSLog(@"%d",[arrlist count]);    for (int i=0; i<[arrlist count]; i++) {        NSDictionary *item=[arrlist objectAtIndex:i];//从数组中取出每个字典        NSString *BrandName=[item objectForKey:@"BrandName"];        NSLog(@"%@",BrandName);    }
//不好意思这个只是别人的简介,我理解一下


0 0