首页新闻招聘找找看知识库
  • 浏览:46 2017-04-02 17:22 来自 甘林梦
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    遇到这样的字典数组字符串
     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"]);
                 
            }

    原文连接

登录后才能评论,请先登录注册