我从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
为空。哪里我错了?