【问题标题】:Facebook KeyNotFoundException Even Though the Key ExistsFacebook KeyNotFoundException 即使密钥存在
【发布时间】:2014-10-23 00:57:01
【问题描述】:

所以我正在使用 Facebook Unity API,但不知道为什么会收到 KeyNotFoundException: The given key was not present in the dictionary.

我正在尝试获取用户的姓氏。名字工作正常。我在前面的行中打印了 Facebook 响应,其中包含“last_name”键,但我仍然得到异常。

void APICallback(){
    Dictionary<string,string> profile = Util.DeserializeJSONProfile(result.Text);  
    print (result.Text);
    currentUser["Name"] = profile["first_name"];
    currentUser["LastName"] = profile["last_name"];
}

这是result.Text

{"id":"XXXXXXX","first_name":"David","last_name":"Richard","friends":{"data":[],"summary":{"total_count":58}}}

【问题讨论】:

  • 如果您打印配置文件,它包含什么?
  • System.Collections.Generic.Dictionary`2[System.String,System.String] 我不确定如何在 Unity 中打印完整的字典
  • 遍历它并打印密钥
  • 好的,所以我这样做了,它打印的只是“first_name”键。但结果包括“id”和“last_name”。没看懂

标签: c# facebook dictionary unity3d facebook-unity-sdk


【解决方案1】:

这一定是Util.DerializeJSONProfile 的一个错误,我使用 SimpleJson 解析了result.Text,它运行良好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-07
    • 1970-01-01
    • 2018-08-17
    • 2021-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-10
    相关资源
    最近更新 更多