指定した場所の Twitter からトレンド トピックを取得する方法は既に用意されています。私の質問は、JSON からこのデータを解析して、トレンド トピック リストの名前と URL を出力できるようにする方法です。
Twitter json フィードの応答は次のようになります。
(
{
"as_of" = "2013-08-05T18:16:52Z";
"created_at" = "2013-08-05T18:06:52Z";
locations = (
{
name = "San Francisco";
woeid = 2487956;
}
);
trends = (
{
events = "<null>";
name = "#jaibrooksfollowingsession";
"promoted_content" = "<null>";
query = "%23jaibrooksfollowingsession";
url = "http://twitter.com/search?q=%23jaibrooksfollowingsession";
},
{
events = "<null>";
name = "#megalodon";
"promoted_content" = "<null>";
query = "%23megalodon";
url = "http://twitter.com/search?q=%23megalodon";
},
{
events = "<null>";
name = "#SharkWeek";
"promoted_content" = "<null>";
query = "%23SharkWeek";
url = "http://twitter.com/search?q=%23SharkWeek";
},
{
events = "<null>";
name = "#bartstrike";
"promoted_content" = "<null>";
query = "%23bartstrike";
url = "http://twitter.com/search?q=%23bartstrike";
},
{
events = "<null>";
name = "#mtvhottest";
"promoted_content" = "<null>";
query = "%23mtvhottest";
url = "http://twitter.com/search?q=%23mtvhottest";
},
{
events = "<null>";
name = "Justin Bieber";
"promoted_content" = "<null>";
query = "%22Justin+Bieber%22";
url = "http://twitter.com/search?q=%22Justin+Bieber%22";
},
{
events = "<null>";
name = "Nelson Cruz";
"promoted_content" = "<null>";
query = "%22Nelson+Cruz%22";
url = "http://twitter.com/search?q=%22Nelson+Cruz%22";
},
{
events = "<null>";
name = "The O.C.";
"promoted_content" = "<null>";
query = "%22The+O.C.%22";
url = "http://twitter.com/search?q=%22The+O.C.%22";
},
{
events = "<null>";
name = Biogenesis;
"promoted_content" = "<null>";
query = Biogenesis;
url = "http://twitter.com/search?q=Biogenesis";
},
{
events = "<null>";
name = PEDs;
"promoted_content" = "<null>";
query = PEDs;
url = "http://twitter.com/search?q=PEDs";
}
);
}
)
この応答を jsondata という配列に保存し、この関数を使用して、たとえば最初のトレンド トピックの名前と URL を取得しますが、うまくいきません..名前の値と URL の値が null を出力しています。
- (void) decompose:(NSArray *)jsondata
{
NSString *name = [[jsondata objectAtIndex:0]objectForKey:@"name"];
NSString *url = [[jsondata objectAtIndex:0]objectForKey:@"url"];
NSLog(@"name:%@",name);
NSLog(@"url:%@",url);
}
何か案は?