我下载了 MGTwitterEngine 并添加到我的 iPhone 项目中。它正在连接并获取雕像,我可以通过将它们转储到 NSLog 中来判断它们。但是,我不知道如何解析这些调用,以便将它们添加到表中。它们以 NSString 形式返回,如下所示:
{
"created_at" = 2009-07-25 15:28:41 -0500;
favorited = 0;
id = 65;
source = "<a href=\"http://twitter.com/\">Twitter</a>";
"source_api_request_type" = 0;
text = "The wolf shirt strikes again!! #sdcc :P http://twitpic.com/blz4b";
truncated = 0;
user = {
"created_at" = "Sat Jul 25 20:34:33 +0000 2009";
description = "Host of Tekzilla on Revision3 and Qore on PSN. Also, a geek.";
"favourites_count" = 0;
"followers_count" = 0;
following = false;
"friends_count" = 0;
id = 5;
location = "San Francisco";
name = "Veronica Belmont";
notifications = false;
"profile_background_tile" = false;
"profile_image_url" = "http://blabnow.com/avatar/Twitter_10350_new_twitter_normal.jpg";
protected = 0;
"screen_name" = Veronica;
"statuses_count" = 2;
"time_zone" = UTC;
url = "http://www.veronicabelmont.com";
"utc_offset" = 0;
};
有人用过这个可以告诉我其他人如何在他们的项目中使用它吗?
Thanks
您在控制台中看到的是 NSDictionary 的 NSLog,而不是 NSString。来自马特·格梅尔的MGTwitterEngine 自述文件 http://svn.cocoasourcecode.com/MGTwitterEngine/README.txt:
发送到这些方法的值都是 NSArray,其中包含每个状态或用户或直接消息的 NSDictionary,如果需要的话还可以包含子字典(例如,时间线方法通常返回状态,每个状态都有一个子字典,提供有关状态的信息)发布该状态的用户)。
因此,您传递给 NSLog() 语句的任何对象实际上都是一个字典,您可以通过调用来访问这些字段:
NSString *createdAtDate = [record valueForKey:@"created_at"];
NSString *source = [record valueForKey:@"source"];
// etc...
Where record是对象。请记住,userfield 是一个子词典。您可以通过以下方式访问它:
NSDictionary *userDict = [record valueForKey:@"user"];
NSString *name = [userDict valueForKey:@"name"];
NSString *location = [userDict valueForKey:@"location"];
// etc...
您实际上可以使用请求中返回的 NSArray 作为表视图的数据源,然后只需通过 -cellForRowAtIndexPath 表视图委托中的索引提取所需的数据源。
此致,
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)