A simple Save/Load data ?

Hi, there
i’d like to make a creation tool for my project.
it’s a simple [save/load/edit] a data file.

[System.Serializable]
public class Character{
   public int id;
   public string name;
}
public class Character_Create:EditorWindow{
  private List<Character> data = new List<Characer>();
  private Character input = new Character();

  void OnGUI(){
   input.id = EditorGUILayout.IntField ("Character ID", input.id);
   input.name = EditorGUILayout.TextField ("Character Name", input.name);

   if(GUILayout.Button("Create")){
     data.Add(input);
   }
  }
}

this is my problem.
1)Is there easy way to save/load a List<> in to a file.
and any function to search a member of List<> by using ID to reference ?
2)what if i use Stream Read/Writer on other platform such a android ?

or any idea that can make it easier to build a Database file.
Thankyou.

A simple way to do this is using UnityEngine.JsonUtility.

string json = JsonUtility.ToJson(myObject);
System.IO.File.WriteAllText(path, json);

https://docs.unity3d.com/Manual/JSONSerialization.html

i try this.

if(GUILayout.Button("Create",GUILayout.Height(20))){
            chaDatabase.Add (cha);
            data = JsonUtility.ToJson (chaDatabase);
            MonoBehaviour.print (data);
            System.IO.File.WriteAllText ("Assets/Script/Database/Character", data);
        }

My List is not empty. but when i use ‘data = JsonUtility.ToJson (chaDatabase);’
the print out is “{ }”

http://answers.unity3d.com/questions/1123326/jsonutility-array-not-supported.html

You need to wrap the list in a class, for example:

[Serializable]
public class CharacterList
{
    public List<Character> Characters = new List<Character>();
}

Then to serialise to JSON:

characterList = new CharacterList();
characterList.Add(character);
json = JsonUtility.ToJson(characterList);

-sam