I'm having an issue with Unity's FromJson method. From the error I'm assuming that there's something wrong with the JSON that I wrote, but I can't for the life of me figure out what it is. First, here's the error
ArgumentException: JSON parse error: Invalid value.
UnityEngine.JsonUtility.FromJson[ShipTypes] (System.String json) (at C:/buildslave/unity/build/artifacts/generated/bindings_old/common/JSONSerialize/JsonUtilityBindings.gen.cs:25)
DataLoader.LoadShipsFromJSON () (at Assets/Scripts/Data/DataLoader.cs:38)
DataLoader.Awake () (at Assets/Scripts/Data/DataLoader.cs:19)
Next, the code (the final line is Dataloader.cs:38)
ShipTypes shipTypes;
string path = Application.streamingAssetsPath + "/ShipTypes.json";
shipTypes = JsonUtility.FromJson<ShipTypes>(path);
Here are my classes
[System.Serializable]
public class ShipTypes
{
public List<Ship> ships;
}
[System.Serializable]
public class Ship
{
public string name;
public int attack;
public int defense;
public int speed;
public int range;
}
And finally here is my JSON
{
"ships" :
[
{
"name": "Corvette",
"attack" : 2,
"defense" : 7,
"speed" : 20,
"range" : 8
},
{
"name": "Frigate",
"attack" : 4,
"defense" : 6,
"speed" : 10,
"range" : 8
},
{
"name": "Destroyer",
"attack" : 8,
"defense" : 8,
"speed" : 10,
"range" : 8
},
{
"name": "Dreadnought",
"attack" : 14,
"defense" : 10,
"speed" : 7,
"range" : 8
},
{
"name": "Battleship",
"attack" : 20,
"defense" : 12,
"speed" : 5,
"range" : 8
}
]
}
Thank you very much.