首页 > 移动平台 > 详细

iOS 解析son串

时间:2016-04-01 17:55:09      阅读:237      评论:0      收藏:0      [点我收藏+]
NSString *json = @"[{\"name\":\"a1\",\"items\":[{\"x1\":\"item1\",\"x2\":\"item2\"}]},{\"name\":\"a2\",\"items\":[{\"x1\":\"item11\",\"x2\":\"item22\"}]}]" ;
    
    NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding];
    
    NSMutableDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    
    for (NSMutableDictionary *row in dict) {
        NSString *name = [row objectForKey:@"name"];
        NSMutableArray *items = [row objectForKey:@"items"];
        NSMutableDictionary *dict1 = items[0];
        NSLog(@"name=%@,x1=%@,x2=%@",name,[dict1 objectForKey:@"x1"],[dict1 objectForKey:@"x2"]);
        
    }

json格式:不说了,自己看,该字典就字典,该数组就数组。

[
    {
        "name": "a1",
        "items": [
            {
                "x1": "item1",
                "x2": "item2"
            }
        ]
    },
    {
        "name": "a2",
        "items": [
            {
                "x1": "item11",
                "x2": "item22"
            }
        ]
    }
]

 

iOS 解析son串

原文:http://www.cnblogs.com/youyuan1980/p/5345680.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!