JSON数组字典解析
遇到这样的字典数组字符串 priceRange = "[{\"id\":149075584861800,\"price\":9.9,\"num\":100},{\"id\":149075584861801,\"price\":9,\"num\":1000},{\"id\":149075584861902,\"price\":8,\"num\":10000},{\"id\":149075584861903,\"price\":7,\"num\":100000}]"; 解析的核心代码如下: id json = [NSJSONSerialization JSONObjectWithData:[priceRange dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments | NSJSONReadingMutableLeaves | NSJSONReadingMutableContainers error:nil]; if ([json isKindOfClass:[NSArray class]]) { NSArray *array = (NSArray*)json; for (NSDictionary *dict in array) { JGLog(@"price:%@",dict[@"price"]); }
解析结果如下: