So, I was doing some testing with trying to set up nested values in litJSON, and I feel I might have gotten somewhere, but I’ve run across this error, and have no idea how to solve the issue.
SaveToJSON.cs
using UnityEngine;
using System.Collections.Generic;
using System.IO;
using System;
using LitJson;
public class SaveToJSON : MonoBehaviour {
void Update () {
if (Input.GetKeyDown(KeyCode.O)) {
PedestalSave();
} else if (Input.GetKeyDown(KeyCode.P)) {
PedestalLoad();
}
}
void PedestalSave () {
Pedestal p = new Pedestal();
p.list = new List<IDHolder>();
p.list.Add(new IDHolder() {
valueName = "id",
valueInt = 0,
});
p.list.Add(new IDHolder() {
valueName = "aggression",
valueBool = false
});
string json_p = JsonMapper.ToJson(p);
Debug.Log(json_p);
File.WriteAllText(Application.dataPath + "/Saves/test.json", json_p);
}
void PedestalLoad () {
string jsonString = File.ReadAllText(Application.dataPath + "/Saves/test.json");
JsonData jsonData = JsonMapper.ToObject(jsonString);
Debug.Log(jsonData["list"][0]["power"]);
}
}
public struct Pedestal {
public List<IDHolder> list { get; set; }
}
[Serializable]
public struct IDHolder {
public string valueName { get; set; }
public string valueString { get; set; }
public int valueInt { get; set; }
public float valueFloat { get; set; }
public bool valueBool { get; set; }
}
Any ideas on how to fix this, or if I’m just a noob, and I’m completely missing something so obvious?