unity save list to json 1

unity save list to json

public class MyList {
	public List list;

var class = new MyList();
var outputString = JsonUtility.ToJson(class);
File.WriteAllText("C:\\MyFile.json", outputString);

//In reverse, you can deserialize anything doing this:
var inputString = File.ReadAllText("C:\\MyFile.json");
var class = JsonUtility.FromJson(inputString);

Here is what the above code is Doing:
1. Create a class that has a list of whatever you want to serialize.
2. Create an instance of that class.
3. Serialize the class to a string.
4. Write the string to a file.
5. Read the string from the file.
6. Deserialize the string into an instance of the class.

Similar Posts