2011-11-22 42 views
0

我的WS返回简单的JSON这样的:如何从json保存在nsstring中获取一些值?

{ 
    "thumbnail_url": "http://something.com/photos/003/582/test-tiny.jpg?1321956139", 
    "success": true, 
    "photo_url": "http://something.com/photos/003/582/test-medium.jpg?1321956139", 
    "big_photo_url": "http://something.com/photos/003/582/test-big.jpg?1321956139" 
} 

我得到这个NSData的从NSURLConnection的。我知道如何从NSData制作NSString。我想为“photo_url”键获得价值。

它如何做到这一点?

回答

0

您必须使用SBJSON框架来获取photo_url的值。

在SBJSON框架中有一个返回字符串的NSMutableDictionary的方法。

你可以像这样使用这个将返回NSMutableDictionary的[string JSONValue]

之后的使用将被从这个代码获得价值[dict valueForKey:@"photo_url"]

感谢,

MinuMaster

0

使用TouchJSONSBJson解析器来解析此问题。

+0

我会sugest [JSONkit(https://github.com/johnezang/JSONKit),因为它是那里的斋戒之物。这里是解析JSON的一些很好的信息:http://triplesoftware.nl/2011/08/json-parsing/ – rckoenes

0

对于iOS 5,只有您可以使用内置的NSJSONSerialization类。

如果您需要支持iOS4,那么JSONKit是一个很好的解决方案。

然后,您可以查询您的结果像一个正常的字典。