JsonUtility.ToJson使用时要注意的地方:
1.自定义的类需要序列化;
2.自定义类的变量public string name;不能写成public string name{get;set;},否则此变量无法序列化。
using System;//引入
[Serializable]//加上此处
public class Per
{
public string name;//此处不能写成public string name{get;set;},否则此变量无法序列化。
public int age;
public Per(string _name, int _age)
{
name = _name;
age = _age;
}
}