为什么JsonUtility不反序列化名为'name'的字段?

时间:2017-12-03 18:42:43

标签: c# json unity3d

我从Google Translate API v2收到了这个json:

{
  "data": {
    "languages": [
         {
           "language": "af",
           "name": "Afrikaans"
         }
      ]
   }
}

尝试用这种方式反序列化它:

[System.Serializable]
public class LanguageChoice
{
    public string name;
    public string language;
}

[System.Serializable]
public class LanguageChoicesResponseData
{
    public List<LanguageChoice> languages;
}

[System.Serializable]
public class LanguageChoicesResponse
{
    public LanguageChoicesResponseData data;

    public static LanguageChoicesResponse CreateFromJSON(string json)
    {
        return JsonUtility.FromJson<LanguageChoicesResponse>(json);
    }
}
调用LanguageChoicesResponse.CreateFromJSON(json)字段language后,

填写正确但name为空。哪里我错了?

0 个答案:

没有答案