如何解析数组?

问题描述:

我有一个应用程序,我从web服务获得这样的响应。谁能告诉我如何分析这使其作为单独的字符串"Info":如何解析数组?

{ 
    "name":"gdgdgdgd", 
    "desc":"Cosmopolitan life, adventurous outlook, 'been there done that' attitude, and yet the way the life ...", 
    "address1":" 2nd A Main ", 
    "address2":" Layout," 
}, 
+2

使用NSJSONSerialization。 – nhahtdh 2012-07-11 05:26:31

+0

你有这个工作吗? – bryanmac 2012-09-01 13:05:03

这是一个对象的JSON表示。

在iOS 5中,JSON类我们添加为NSJSONSerialization

这里有一个教程:

http://www.raywenderlich.com/5492/working-with-json-in-ios-5

这里是另一个线程讨论其他选项,以及像JSONKit,YAJL

Native JSON support in iOS?

这样做使用json库

NSMutableDictionary * listd = [dict objectForKey:@“merchantInfo”];

if([listd isKindOfClass:[NSDictionary class]]) 

{ 

    stringshopname=[listd objectForKey:@"name"]; 
    stringshopdesc=[listd objectForKey:@"desc"]; 


}