Fork me on GitHub

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"]);
            
        }

 解析结果如下:

 

posted @ 2017-03-31 09:01  极度恐慌_JG  阅读(2025)  评论(0编辑  收藏  举报