- Home /
Question by
Benjamin-Sims · Apr 21, 2016 at 05:17 PM ·
unity 5unity5litjson
JsonException: Max allowed object depth reached while trying to export from type System.Single
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?
Comment
Answer by AleksandrZombie · Dec 26, 2016 at 05:59 PM
the problem is the float value man, change for a double.
This worked for me ! But I would like to know why. Are float numbres not supported by litjson? Anyways, thanks you !
try this litjson dll, can read/save float values https://mega.nz/#!bpRgVBgI!2TT_PD_0FW$$anonymous$$pAD2GFsiVO7_OV8cLIjEobULEfJo9xzA