Unity自带api解析json字符串

1.LitJson
2.Unity自带api


public class(struct) JsonData{
	public string name;
	public int age;
}

public class JsonTest : MonoBehaviour{
	public string data = 
	// "{\"name\":\"Bob\",\"age\":\"23\"}";
	// "{"+"name"+":"+"Bob"+","+"age"+":"+"23"+"}";
	// "name"+":"+"Bob"+","+"age"+":"+"23";
	// "{name:Bob,age:23}";
	// "name:Bob,age:23";
	//这几种写法都可以

   void Start(){
	   JsonData jsonData = JsonUtility.FromJson<JsonData>(data);
	   Debug.Log(jsonData.name + jsonData.age);
   }
}

你可能感兴趣的:(Unity)