我这里不过是借花献佛,案例官网就有.
using UnityEngine;
using System.Collections; public class json : MonoBehaviour { public class JsonInfo
{
public int id;
public string name;
public int age;
} void Start () {
JsonInfo Info=new JsonInfo();
Info.id = ;
Info.name = "WenanLee";
Info.age = ; print(ToJson(Info)); print(FromJson(ToJson(Info)).name);
} string ToJson(JsonInfo info)
{
return JsonUtility.ToJson(info);
} JsonInfo FromJson(string jsonStr)
{
return JsonUtility.FromJson<JsonInfo>(jsonStr);
}
}