我目前正致力于在iOS应用程序中解析来自Twitter的推文。我的应用程序目前可以使用search.twitter.com/search.json?...
API调用执行搜索,我的应用程序可以解析这些推文,并为每条推文选择所需的所有数据。我处于现在正在尝试获取用户时间轴的阶段,但似乎无法找到稳定的方式来解析用户时间轴API调用中返回的对象。解析Twitter获取状态目标C
随着搜索功能(例如返回在底部对象:https://dev.twitter.com/docs/api/1/get/search)我可以通过所有这些结果,像这样的选择valueForKey:(@"results")
和循环解析:
//jSONText is the returned result from the API in NSDictionary format
NSArray *resultTweetsJSON = [jSONText valueForKey:(@"results")];
for (int tweetIndex=0; tweetIndex<[resultTweetsJSON count]; tweetIndex++) {
//Loop through and pull out raw tweet content for a specific tweet
NSString *rawTweetContent = [resultTweetsJSON objectAtIndex:tweetIndex];
//Build a custom tweet object using that content
Tweet *singleTweet = [[Tweet alloc] initWithResultsContent:rawTweetContent];
}
我希望我可以执行相同或相似的东西,但我似乎无法找到与时间线中返回的数据一起使用的好钥匙(例如,返回的数据靠近底部:https://dev.twitter.com/docs/api/1/get/statuses/user_timeline)。
正如你所看到的,user_time
结果集不包含我可以查询的很好的“results
”键。
如何轻松选择和解析来自调用Get/Statuses/User_Timeline
Twitter API的数据并将其转换为NSArray,以便我可以循环并提取推文?网上的一切似乎都使用旧技术。我发现this tutorial,但它看起来像从Twitter作为一个NSData对象而不是一个NSDictionary对象,我相信NSDictionary是最新的方式来做到这一点。
这里的东西我想威力工作:
//No valueForKey to use, so perhaps use ""?
NSArray *timeline = [jSONText valueForKey:(@"")];
for (int i=0; i<[timeline count]; i++) {
//Looping through each "object" of the timeline, grab the tweet content then fill user content
//Grab the "user" object from the timeline object we're looking at
NSString *rawUserContent = [[timeline objectAtIndex:i] valueForKey:(@"user")];
//NSString *rawUserContent = [timeline valueForKey:(@"user")]; - Maybe this?
//Do whatever else I need to do here...
}
谢谢你回答你自己的问题:) –