Json
を使用して文字列を逆シリアル化しようとするとJsonFx
、値 null が返されます。
これが私のJson文字列です
{
"PlayerID": 123,
"PlayerName": "Avi",
"DemiGods": {
"Red": {
"Name": "Red",
"Level": 20,
"Attack": 5,
"Dodge": 1,
"Defence": 10,
"Speed": 10
},
"Blue": {
"Name": "Blue",
"Level": 20,
"Attack": 5,
"Dodge": 1,
"Defence": 10,
"Speed": 10
},
"Green": {
"Name": "Green",
"Level": 20,
"Attack": 5,
"Dodge": 1,
"Defence": 10,
"Speed": 10
},
"Light": {
"Name": "Light",
"Level": 20,
"Attack": 5,
"Dodge": 1,
"Defence": 10,
"Speed": 10
},
"Dark": {
"Name": "Dark",
"Level": 20,
"Attack": 5,
"Dodge": 1,
"Defence": 10,
"Speed": 10
}
},
"PlayerGrid": {
"Red": {
"x": 0,
"y": 1
},
"Blue": {
"x": 1,
"y": 1
},
"Green": {
"x": 2,
"y": 1
},
"Light": {
"x": 2,
"y": 2
},
"Dark": {
"x": 3,
"y": 2
}
},
"AIGrid": {
"Red": {
"x": 0,
"y": 1
},
"Blue": {
"x": 1,
"y": 1
},
"Green": {
"x": 2,
"y": 1
},
"Light": {
"x": 2,
"y": 2
},
"Dark":
{
"x": 3,
"y": 2
}
}
}
This is my class where i stores the data from Json
public class UnitsInfo :MonoBehaviour
{
public string PlayerName;
public int PlayerID;
public List<DemiGods> demigodslist = new List<DemiGods>();
public List<GridData> playerGridlist = new List<GridData>();
public List<GridData> AIGridList = new List<GridData>();
public UnitsInfo()
{
Debug.Log("Default Constructor");
}
public UnitsInfo(string _name, int id, List<DemiGods> Godlist, List<GridData> plist, List<GridData> AIlist)
{
PlayerName = _name;
PlayerID = id;
demigodslist = Godlist;
playerGridlist = plist;
AIGridList = AIlist;
}
public class DemiGods
{
public string Name;
public int Level;
public float Attack;
public float Dodge;
public float Defence;
public float Speed;
public DemiGods()
{
Debug.Log("DemIGOds DeFALUT ConsTruCtoR");
}
public DemiGods(string _name, int _lvl, float _attack, float _dodge, float _Defence, float _speed)
{
Name = _name;
Level = _lvl;
Attack = _attack;
Dodge = _dodge;
Defence = _Defence;
Speed = _speed;
}
}
public class GridData
{
public Vector2 pos;
public GridData() { Debug.Log("Grid DAta DeFALUT ConsTruCtoR"); }
public GridData(int x, int y)
{
pos.x = x;
pos.y = y;
}
}
}
This is where is deserialize data
public class JsonData: MonoBehaviour
{
public string JSONString;
void Start()
{
UnitsInfo HerosList = JsonReader.Deserialize<UnitsInfo>(JSONString);
Debug.Log(HerosList);
}
}
The Debug.log return null. Where im going wrong??
Thanks in Advance