【发布时间】:2018-12-26 13:43:00
【问题描述】:
我在 Unity 引擎中使用 JSONUtility 练习 JSON 反序列化。当属性为字符串时,我在 stackoverflow(Link) 的帮助下使用 POCO 类解决了一些示例。我使用确切名称解决了以下 JSON.Link在 POCO 类中。但是当 JSON 属性包含如下整数时。
{
"1": {
"Armor": 1,
"Strenght": 1
},
"0": {
"Armor": 1,
"Mana": 2,
"Strenght": 1,
"Health": 1,
"Power": 1
}
}
以类似的方式解决没有成功。根据我得到的反馈,我必须使用字典。
IEnumerator GetExampleValues()
{
string URLss = "http://www.json-generator.com/api/json/get/bOQGnptixu?indent=2";
WWW readjson = new WWW(URLss);
yield return readjson;
Debug.Log("ReadJSON"+readjson.text);
}
下面是我的 POCO 课
using System.Collections.Generic;
[System.Serializable]
public class Exampleget
{
public int Power;
public int Mana;
public int Strenght;
public int Armor;
public int Health;
}
public class GetNumbers
{
public List<Exampleget> onevalues;
}
【问题讨论】: