开发者

accessing parsed JSON on the iPhone SDK

I've been following the great tutorial about (iPhone, json and Flickr API and I did manage to ac开发者_如何学Pythoncess the parsed json info just fine.

Now I'm trying to do the same thing with the Twitter API, and I am able to get the json info and parse it, but I can't seem to access it like in Flickr.

I noticed that the json info that is retrieved from Twitter is a little different from Flickr.

The Flickr json info starts straight with a curly braces ({), while the Twitter json info starts with a square bracket and then a curly braces ([{). I understand that it means it's an array inside the json info, but I don't know how to access it.

In the Flickr example, I access the objects like so (the second line takes the number of pages Flickr has reported):

NSDictionary *results = [jsonString JSONValue];
pagesString = [[results objectForKey:@"photos"] objectForKey:@"pages"];

but I can't seem to access the Twitter response in the same way...

Does anyone know of a solution?

(here's an example of the Twitter JSON response: api.twitter.com/1/statuses/public_timeline.json )

Thanks a bunch!


Have you tried:

NSArray *results = [jsonString JSONValue];
NSDictionary *first = [results objectAtIndex:0];
NSLog(@"screen name = %@", [first objectForKey:@"screen_name"]);

etc?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜