我有这个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));
});
如何将这些数据解析为字符串?
答案 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"];