Json item list serialization problem
I'm trying to serialize my inventory items list, but I get an empty json file having 12 empty spaces, that is right because my items list has 12 items, but item values are not saved, could anyone suggest me what's wrong?
My script is: //this is the items list I would like to serialize:
public List items = new List();
// I have created a wrapping class like this one:
[System.Serializable] public class WrappingClass { public List items; }
// To serialize my list I'm using this:
public void Save()
{
string filename = Path.Combine(Application.dataPath + "/StreamingAssets/itList.json");
var variable = new WrappingClass() { items = items };
string jsonData = JsonUtility.ToJson(variable, true);
if (File.Exists(filename))
{
File.Delete(filename);
Debug.Log("File del");
}
File.WriteAllText(filename, jsonData);
Debug.Log("FileSaved");
}
But what I get is this: { "items": [ {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {} ] }
This is what is saved to the json file, 12 empty spaces but no item data, in my list an empty item is "-1" and other items ids are "0" "1" "2" and so on. Could please anyone tell me what's wrong? Thanks a lot.
Your answer
Follow this Question
Related Questions
Null Exception while serialize json string into txt file 0 Answers
Serialize gameobject children behaviours 0 Answers
[SOLVED] JSON Serialization of Derived Classes 2 Answers
UnityException: Failed to run serialization 0 Answers
Nested dictionary serialization 0 Answers