I've currently got a json file that looks some what like this called "Monsters.json"
{
"frosline":{
"id":1,
"name":"frosline",
"baseStats":[4, 3, ...],
...}
}
I've also got a MonsterStats class with all the same variables and im having trouble adding more monsters to this json file through code (for example one file may contain the list of monsters that have been caught ala pokemon)
I've tried doing something like:
MonsterStats stats = new MonsterStats(<stats for the monster here>)
JsonData monsterJson = JsonMapper.ToJson(stats);
String oldsave = File.ReadAllText(Application.dataPath + "/Monster.json");
JsonData monsterData = JsonMapper.ToObject(oldsave);
monsterData["newMon"] = monsterJson;
But instead of adding a new object in "newMon", it instead is added as a weird string:
newMon":"{\"id\":0,\"name\":\"player\",\"baseStats\":[10,0,0,0,0,0],\"xpyield\":0,\"evyield\":[0,0,0,0,0,0],\"moves\":[\"Ember\",\"\",\"\",\"\"],\"health\":11,\"stats\":[11,5,5,5,5,5],\"evs\":[0,0,0,0,0,0],\"level\":1,\"xp\":0}"}
I've tried looking for a similar question or a solution but I'm quite new to JSon so it's been difficult to know what to search. This is using litjson if that helps.
What's also annoying me is if I simply print out variable monsterJson it comes out cleanly:
{"id":0,"name":"player","baseStats":[10,0,0,0,0,0],"xpyield":0,"evyield":[0,0,0,0,0,0],"moves":["Ember","","",""],"health":11,"stats":[11,5,5,5,5,5],"evs":[0,0,0,0,0,0],"level":1,"xp":0}