public class mPerson {
public string name;
public int age;
public string ID;
public string[] arr;
List<int> array;
public void Sex() { }
}
class Player
{
public string name;
public int age;
public string ID;
public string[] arr;
List<int> array;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Xml;
public class JsonTools :Editor
{
[MenuItem("Mytools/JSONRun")]
public static void JsonRun() {
mPerson mp = new mPerson();
mp.name = "张三";
mp.ID = "123456";
mp.age = 18;
mp.arr= new string[] { "asd", "sdf", "sdf", "asd", "aasdf" };
List<int> array = new List<int>();
array.Add(1);
array.Add(2);
array.Add(3);
array.Add(4);
array.Add(5);
array.Add(6);
array.Add(7);
array.Add(8);
string str = JsonUtility.ToJson(mp);
Debug.Log(str);
Player p= JsonUtility.FromJson<Player>(str);
Debug.Log(p.name);
Debug.Log(p.age);
Debug.Log(p.ID);
Debug.Log(p.arr[0]);
Debug.Log(p.arr[1]);
Debug.Log(p.arr[2]);
Debug.Log(p.arr[3]);
Debug.Log(p.arr[4]);
Debug.Log(array[0]);
Debug.Log(array[1]);
Debug.Log(array[2]);
Debug.Log(array[3]);
Debug.Log(array[4]);
Debug.Log(array[5]);
Debug.Log(array[6]);
Debug.Log(array[7]);
}
}