码迷,mamicode.com
首页 > 编程语言 > 详细

unity json序列化和反序列化

时间:2019-10-28 14:26:18      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:hid   gen   需要   click   str   public   json序列化   new   ring   

技术图片
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

unity json序列化和反序列化

标签:hid   gen   需要   click   str   public   json序列化   new   ring   

原文地址:https://www.cnblogs.com/G993/p/11751818.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!