Fail to load data from json to list of list.

Sorry to my bad question because i not sure how my question going to write.
I have using JsonUtility to save my data.
Below my code.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

public class SaveLoadFunction : MonoBehaviour {

	AnyScript anyScript;
	void Start()
		anyScript = AnyScript.instance;

	private Save CreateSaveData()
		Save save = new Save ();

		for (int i = 0; i < anyScript.ListsOfVariable.Count; i++)
			save.variableName.Add (anyScript.ListsOfVariable *.variableName);*

_ save.intVariable.Add (anyScript.ListsOfVariable .intVariable);_
_ save.floatVariable.Add (anyScript.ListsOfVariable .floatVariable);
save.boolVariable.Add (anyScript.ListsOfVariable .boolVariable);
save.randomPosition.Add (anyScript.ListsOfVariable .randomPosition);
for (int j = 0; j < anyScript.ListsOfVariable .intListVariable.Count; j++)
* {
save.intListVariable.Add (anyScript.ListsOfVariable .intListVariable [j]);

* return save;*
* }*

* public void SaveAsJSON()*
* {*
* Save save = CreateSaveData ();*
* string json = JsonUtility.ToJson (save);*
* string filePath = Application.dataPath + “/”;*
* File.WriteAllText (filePath, json);*

* Debug.Log ("Saving as JSON: " + json);*
* }*

* public void LoadFromJSON()*
* {*
* string filePath = Application.dataPath + “/”;*

* if (File.Exists (filePath))*
* {*
* string json = File.ReadAllText (filePath);*
* Save save = JsonUtility.FromJson (json);*

* for (int i = 0; i < anyScript.ListsOfVariable.Count; i++)*
* {*
anyScript.ListsOfVariable .variableName = save.variableName ;
anyScript.ListsOfVariable .intVariable = save.intVariable ;
anyScript.ListsOfVariable .floatVariable = save.floatVariable ;
anyScript.ListsOfVariable .boolVariable = save.boolVariable ;
anyScript.ListsOfVariable .randomPosition = save.randomPosition ;
* //???*
_ for (int j = 0; j < anyScript.ListsOfVariable .intListVariable.Count; j++)
* {
anyScript.ListsOfVariable .intListVariable [j] = save.intListVariable [j];
Debug.Log (“Saving Variable Loaded”);

* {
Debug.Log (“No Saving Variable Saved”);

By using code above i have manage to save all the data from the anyscript and success to load most of the data except ListsOfVariable.
The AnyScript data will be randomize every time play.
Below will be shown the image of before load and after load.
Can be see that after load all of the ListsofVariable will only load first 3 number that saved.
How to solve this???

We don’t know how your Save class looks like. However it seems that you just flattened all the data into a few one dimensional arrays. You just concatenate all the int values into one long list of integers. If you are sure that each item actually has 3 values you could pull out the values correctly. However if one element could have 2 another 4 or 7 elements it’s impossible to tell which int values belong to which item.

Why don’t you model your data as actual objects in json? Json is a structured object notation language. We also don’t know how the serializable class that is stored inside your “ListsOfVariable” list looks like. Though i don’t see a reason why you couldn’t store those directly as json. The only thing that’s important is that Unity’s JsonUtility does only support an object as root element. So you can not directly save a List / array (which json itself does support). So you should be able to do:

public class Save
    public List<YourItemType> allItems;

To save your data you could just do:

Save save = new Save();
save.allItems = anyScript.ListsOfVariable;
string json = JsonUtility.ToJson (save);
string filePath = Application.dataPath + "/";
File.WriteAllText (filePath, json);

To load, just do:

Save save = JsonUtility.FromJson<Save> (json);
anyScript.ListsOfVariable = save.allItems;