怎么在unity3D工程中导入Newtonsoft.Json
unity旧版本自带的json接口太难用了(JsonUtility),不能序列化字典和列表等对象,只能序列化基础类型对象,所以基本等于没有。
- Newtonsoft.Json-for-Unity-master
的github下载地址点这里 - 或者这个链接,据说是2022版本之后得到了unity官方的支持
 
在git上下载Newtonsoft.Json-for-Unity-master的压缩文件(.zip),解压之后,复制到unity3D工程的Asset/Plugins文件夹下就可以用了,
 
 在脚本中就可以使用Newtonsoft.Json了,例如下述代码:
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using System.IO;
public class Player : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        string json = JsonConvert.SerializeObject(
            new Dictionary<string, string> {
                { "123", "123" },{ "456", "456" }, });
        string path = Application.persistentDataPath + "/saveFile.json";
        File.WriteAllText(path, json);
    }
    // Update is called once per frame
    void Update()
    {
        
    }
}
 
祝好!








![[SSM]MyBatis的缓存与逆向工程](https://img-blog.csdnimg.cn/23f28a3097a44badb6af0b1e47d4295c.png)










