unity json序列化和反序列化


using Newtonsoft.Json;
using System.Collections.Generic;
using UnityEngine;

public class JsonDe : MonoBehaviour
{
    public class Produc
    {
        public string name = "sdf";
        public int a = 1;
        public bool b = true;
        public float c = 2.1f;
        public Dictionary<string, string> dic = new Dictionary<string, string> { { "sdfsd", "654" }, { "dfsdf", "354" } };
        public string[] ss = { "sdfsdf", "3213", "sdfsdf" };
        public int[,] ves = new int[1, 2] { { 1, 2 } };

    }
    
    void Start()
    {
        Produc produc = new Produc();

        string json = JsonConvert.SerializeObject(produc);

        Debug.Log(json);

        Produc m = JsonConvert.DeserializeObject<Produc>(json);

        Debug.Log(m.ves[0, 0]);

    }

   
}
View Code

需要用到Newtonsoft.Json.dll, 放到Plugins文件夾下面 

csdn下載鏈接  https://download.csdn.net/download/gp1320099322/11932181


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM