如何将Facebook得分数据解析为Monotouch iOS中的Strings?

时间:2013-09-28 20:17:24

标签: facebook xamarin.ios

我有这个facebook数据:

    {
  "data": [
    {
      "user": {
        "name": "James Pearce", 
        "id": "738229837"
      }, 
      "score": 20, 
      "application": {
        "name": "Bubble Safari", 
        "namespace": "bubblesafari", 
        "id": "164731003644283"
      }
    },
    ...

我想将这些数据解析成字符串。我从结果对象的侦听器获取此数据:

FBRequestConnection.StartWithGraphPath(AppId+"/scores?fields=score,user",null,"GET", 
(FBRequestConnection connection, NSObject result, NSError err) => {
    if (err != null)
        ShowMessage("Error", string.Format ("Error:\nDomain: {0}\nCode: {1}\nDescription: {2}", err.Domain, (FBErrorCode)err.Code, err.Description));
});

如何将这些数据解析为字符串?

1 个答案:

答案 0 :(得分:3)

这是Json格式的数据。使用JSON.Net组件解析数据,然后您可以访问各个成员。

string data = ... whatever the FB response is ...
var parsed = JObject.Parse (data);

var user = data["data"]["user"];
var name = user["name"];
var score = data["data"]["score"];