来自Facebook和Unity的Json [英] Json From Facebook and Unity
问题描述
我统一从Facebook SDK返回了一个json,如下所示:
I have a json returned from the Facebook SDK in unity that looks like this:
{"name":"Name_of_person", "id":"989988988"}
我看了一下原始的JSON,这就是我通过Graph API提交对该信息的查询后的样子.
I've taken a look at the raw JSON and this is what it looks like after I submit a query for that information via the Graph API.
到目前为止,我正在尝试反序列化json:
So far I am trying to deserialize the json as such:
void DealWithProfileInfo(IGraphResult result){
Dictionary<string,string> profile = JSON.Deserialize (result.RawResult) as Dictionary<string,string>;
scoresText.text = profile ["first_name"];
idText.text = profile["id"];
DealWithProfileInfo是我从FB.API调用中获取的回调方法.
DealWithProfileInfo being my callback method from the FB.API call.
由于某种原因,所有信息均未显示,我不确定为什么.
for some reason none of the information gets displayed and I am not sure why.
我错过了什么吗?还是我解析的数据错误?
Am I missing something? Or maybe I am parsing the data wrong?
推荐答案
实际上,根据我的个人经验,每当我弄混Facebook SDK或Unity3d中的任何其他JSON时,无论JSON的层次如何,它总是返回Dictionary<string,object>
.因此,开发人员必须走上楼梯
Actually it is my personal experience that whenever I mess up with Facebook SDK or any other JSON in Unity3d, then what ever the hierarchy of JSON would be, it always returns Dictionary<string,object>
. So developer have to come through that stairs
因此,在您的情况下,应声明并强制转换为Dictionary<string,object>
而不是Dictionary<string,string>
,然后将该object
转换为string
.
So in your case you should declare and cast to Dictionary<string,object>
instead of Dictionary<string,string>
then convert that object
to string
.
这篇关于来自Facebook和Unity的Json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!