使用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); }