2012-02-20 80 views
1

在我的-request:didLoad:委託方法中,我的結果是NSLog,但我無法弄清楚內容是什麼?iOS - Facebook SDK,解析結果

看起來像結果是NSArray但它裏面有什麼?我如何解析數據?

日誌的樣本是這樣的:

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

Facebook的iOS的教程,在 「第6步:使用圖形API」,說

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.

在你例如,打印出由NSLog的內部「()」是一個NSArray的一部分,而裏面的一切「{}」(其也具有捎帶密鑰)是一個NSDictionary的一部分,因此通過鍵訪問(名稱)。

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