找到的一个Unity C#的Json库 支持各个平台

找到的一个Unity C#的Json库 支持各个平台 

https://github.com/facebook-csharp-sdk/simple-json/tree/master/src/SimpleJson

例子地址:

https://github.com/facebook-csharp-sdk/simple-json/wiki/Getting-Started

        JsonArray tja=new JsonArray();
        tja.Add("1");
        tja.Add("2");
        tja.Add("3");

        JsonArray tja1=new JsonArray();
        tja1.Add("11");
        tja1.Add("22");
        tja1.Add("33");

        tja.Add(tja1);

        string json1=tja.ToString();

        Debug.Log("JsonArray------------");
        Debug.Log("json:"+json1);
        JsonArray desTja1=(JsonArray) SimpleJson.SimpleJson.DeserializeObject(json1);

        Debug.Log("JsonArray Deserialize---------");
        for(int i=0;i<desTja1.Count;i++)
        {
            Debug.Log(desTja1[i]);
            if(i==desTja1.Count-1)
            {
                JsonArray desTja2=(JsonArray) SimpleJson.SimpleJson.DeserializeObject(desTja1[i].ToString());
                for(int j=0;j<desTja2.Count;j++)
                {
                    Debug.Log(desTja2[j]);
                }
            }
        }

        JsonObject tjo=new JsonObject();
        tjo["key1"]="1";
        tjo["key2"]="2";

        JsonObject tjo1=new JsonObject();
        tjo1["key3"]="33333";

        tjo["key3"]=tjo1.ToString();

        string json2=tjo.ToString();
        Debug.Log("JsonObject------------");
        Debug.Log("json:"+json2);

        JsonObject desJo1=(JsonObject) SimpleJson.SimpleJson.DeserializeObject(json2);

        Debug.Log("JsonObject Deserialize---------");
        Debug.Log("tjo key1:"+desJo1["key1"]);
        Debug.Log("tjo key2:"+desJo1["key2"]);

        JsonObject desJo2=(JsonObject) SimpleJson.SimpleJson.DeserializeObject(desJo1["key3"].ToString());

        Debug.Log("tjo key3:"+desJo1["key3"]);

        Debug.Log("tjo1 key3:"+desJo2["key3"]);

114631_T2d7_2246811.png

转载于:https://my.oschina.net/happyaser/blog/323670

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值