问题
I get this from a sample Flickr response in their api site:
jsonFlickrApi({"method":{"_content":"flickr.test.echo"}, "format":{"_content":"json"}, "api_key":{"_content":"8038f7f7d7151ccbf6df2aa10b1b35ae"}, "stat":"ok"})
I can see the dictionary in there, right after the words jsonFlickApi. But how do I get rid of that leading text and put the dictionary into my NSDictionary?
回答1:
Use the NSJSONSerialization class to parse the JSON data.
Edit: The jsonFlickrApi(...)
indicates that you're using a JSONP endpoint to talk to Flickr. You don't need this; a plain JSON endpoint is fine. According to this Flickr API documentation you can fix this by including the parameter nojsoncallback
with the value 1
when you make your request.
来源:https://stackoverflow.com/questions/15930932/how-do-i-parse-this-flickr-response