私はかなりうまくいったタッチJSONを使用しています。配列を取得して辞書に入れ、touchJSON 経由でシリアル化し、http 経由で送信することができました。
リターンエンドで、データを受け取り、それを辞書に入れました(JSONの例としてtwitterのtrend.jsonを使用しています)。
ディクショナリ オブジェクトからトレンドの値を取得しようとすると、次のようになります。
2010-08-02 00:23:31.069 rateMyTaxi[30610:207] ANSWER: (
{
name = "Fried Chicken Flu";
url = "http://search.twitter.com/search?q=Fried+Chicken+Flu";
},
{
name = "Lisa Simpson";
url = "http://search.twitter.com/search?q=Lisa+Simpson";
},
{
name = "#breakuplines";
url = "http://search.twitter.com/search?q=%23breakuplines";
},
{
name = "#thingsuglypeopledo";
url = "http://search.twitter.com/search?q=%23thingsuglypeopledo";
},
{
name = "Inception";
url = "http://search.twitter.com/search?q=Inception";
},
{
name = "#sharkweek";
url = "http://search.twitter.com/search?q=%23sharkweek";
},
{
name = "JailbreakMe";
url = "http://search.twitter.com/search?q=JailbreakMe";
},
{
name = "Kourtney";
url = "http://search.twitter.com/search?q=Kourtney";
},
{
name = "Shark";
url = "http://search.twitter.com/search?q=Shark";
},
{
name = "Boondocks";
url = "http://search.twitter.com/search?q=Boondocks";
}
)
名前や URL の値を取得しようとしても、イライラするような結果は得られません。それが私が必要とするデータです。フォーマットされており、傾向を適切に読み取っているため、辞書フォーマットであることがわかります。私は何かが欠けていると確信しているので、どの方向に従うべきか教えてください。
コードは次のとおりです。
// this is all touch JSON magic. responseString has the full contents of trends.json
NSString *response = [request responseString];
NSLog(@"response value is:%@",response);
NSString *jsonString = response;
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF32BigEndianStringEncoding];
NSError *error = nil;
NSDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
//end of touchJSON. It is in a dictionary now.
NSLog(@"dictionary:%@, error %@", dictionary, error); //http://cl.ly/adb6c6a974c3e70fb51c
NSString *twitterTrends = (NSString *) [dictionary objectForKey:@"trends"];
NSLog(@"ANSWER:%@",twitterTrends); //http://cl.ly/fe270fe7f05a0ea8d478