如何在iOS中解析JSON

时间:2013-03-08 12:02:30

标签: ios json

{"data":[
         "",{"id":"1","nom":"hello","message":["",{"id":1,"nom":"dad"}]},
            {"id":"2","nom":"hi","message":["",{"id":"1","nom":"marie"},{"id":"2","nom":"bob"}]}
        ]
} 

如何使用iOS

从中提取数据

2 个答案:

答案 0 :(得分:0)

利用NSJSONSerialization

NSError *jsonError = nil;
id allValues = [NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding]
                                                                      options:0
                                                                        error:&jsonError];

if(jsonError!=nil)
   NSLog(@"Json_Err: %@",jsonError);

NSArray *result = [(NSDictionary*)allValues objectForKey:@"data"];

答案 1 :(得分:0)

为您的项目集成Json sdk并将下面的代码放在这样......

NSStrig *jsonString = @"your json string";
NSDictionary *responseDictionary = [jsonString JSONValue];