码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 解析son串

时间:2016-04-01 17:58:03      阅读:131      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!