using UnityEngine;
using System.Collections;
using LitJson;
public class MyJsonMapper : MonoBehaviour {
class Person
{
public string Name{ set; get;}
public int Age{ set; get;}
}
void ClassToJson()
{
Person p = new Person ();
p.Name = "XiaoMing";
p.Age = 18;
string str = JsonMapper.ToJson (p);
Debug.Log (str);
}
// Use this for initialization
void Start () {
ClassToJson ();
}
void CreateJson()
{
string json = @"
{
""mxy"":{""name"":""Albert"",""artist"":""Sing Song"",""year"":1999,
""tracks"":[""Bistu"",""CSS"",""VR""]}}";
JsonData data = JsonMapper.ToObject (json);
//访问mxy得到一个新的对象,连续访问【“name”】得到新对象name这个key所对应的值
Debug.Log (data["mxy"]["name"]);
Debug.Log (data["mxy"]["year"]);
Debug.Log (data["mxy"]["tracks"][2]);
string name = (string)data ["mxy"] ["name"];
int year = (int)data ["myx"] ["year"];
Debug.Log (name);
Debug.Log (year);
}
// Update is called once per frame
void Update () {
}
}
文章标题
最新推荐文章于 2024-04-22 16:59:44 发布
