2012-02-20 13 views
1

私の-request:didLoad:の代理人の方法で私はNSLogですが、内容は分かりません。iOS - Facebook SDK、結果を解析する

結果はNSArrayですが、その内部には何がありますか?どのようにデータを解析するのですか?

ログのサンプルは次のようになります。https://developers.facebook.com/docs/reference/api/によると

result: (
     { 
     "fql_result_set" =   (
         { 
       uid2 = 1234567; 
      }, 
         { 
       uid2 = 12345678; 
      } 
     ); 
     name = queryID; 
    }, 
     { 
     "fql_result_set" =   (
         { 
       "birthday_date" = "05/12/1987"; 
       name = "John Doe"; 
      }, 
         { 
       "birthday_date" = "03/01/1978"; 
       name = "Jane Doe"; 
      } 
     ); 
     name = queryBirthday; 
    } 
) 

答えて

2

の "ステップ6:グラフAPIの使用" でのFacebookのiOSチュートリアル、

氏は述べています(また、偶然のキーを持っている)あなたの例では、すべてが内部のNSLogで印刷

Note that the server response will be in JSON string format. The SDK uses an open source JSON library https://github.com/stig/json-framework/ to parse the result. If a parsing error occurs, the SDK will callback request:didFailWithError: in your delegate.

A successful request will callback request:didLoad: in your delegate. The result passed to your delegate can be an NSArray, if there are multiple results, or an NSDictionary if there is only a single result.

「()」にNSArrayの一部であり、すべてが内部ながら「{}」はNSDictionaryの一部、従ってキーによってアクセス可能です(名)。

http://developers.facebook.com/docs/mobile/ios/build/

1

、すべての回答は、「JSON-オブジェクトです。これらを解析するには、iOSの5はNSJSONSerializationと呼ばれるクラス(NSJSONSerialization Class Reference

を提供し、次のようにあなたは、通常、それを解析:

NSDictionary *dictionaryJSON = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];