Unity自己的json序列化是不支持字典格式的,但是 json .net库,功能很强大,还支持序列化字典.

下载地址:https://download.csdn.net/download/qq_15017279/10358562

下载地址:https://www.newtonsoft.com/json (可能打不开)

Newtonsoft.Json.dll 拖入unity工程。

写下一段简单的序列化 和 反序列化json的代码:

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

public class TestJSON : MonoBehaviour
{

    void Start()
    {

        Product product = new Product();
        product.dic["键"] = "";
        product.name = "小明";
        string json = JsonConvert.SerializeObject(product);

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

        Debug.Log(json);
        Debug.Log(m.name);
    }


    public class Product
    {
        public string name;
        public Dictionary<string, string> dic = new Dictionary<string, string>();
    }

}

Unity 用JSON库序列化与反序列化类,字典

相关文章:

  • 2022-12-23
  • 2021-12-25
  • 2021-04-08
  • 2021-09-29
  • 2022-01-08
  • 2022-02-21
  • 2022-12-23
猜你喜欢
  • 2021-05-21
  • 2021-10-05
  • 2021-12-26
  • 2021-10-29
相关资源
相似解决方案