LitJson C#JSON解析库
LitJson 的 C#库,真的挺适合在 Unity 里解析 JSON 数据的,是你项目里数据结构多又杂的时候。
和 Unity 自带的 JsonUtility 比,LitJson.dll 用起来更灵活。你可以直接用 JsonMapper.ToObject()
把 JSON 字符串转成 C#对象,写起来省事,解析也挺快。
插件放到 Assets/Plugins
里就行,Unity 会自动加载 DLL。你在脚本里 using LitJson
一下,功能基本都能用上。比如:
string jsonString = "{\"name\":\"John\", \"age\":30}";
JsonData data = JsonMapper.ToObject(jsonString);
string name = (string)data["name"];
int age = (int)data["age"];
反过来要把 C#对象变成 JSON?直接 JsonMapper.ToJson()
搞定,效率还挺高。
如果你平时要做和后端数据交互,或者本地存档、配置啥的,LitJson 确实是个还不错的选择。不想折腾大库,图个轻量干净,它就蛮合适的。
哦对了,别忘了解压 LitJson.dll_解析 json.zip
,把里面的 LitJson.dll
拖到 Plugins
文件夹里,基本就能开工了。
如果你想对比更多做 JSON 的方式,可以看看JsonUtility 和 Newtonsoft.Json 的对比。
LitJson.dll_解析json.zip
预估大小:1个文件
LitJson.dll_解析json
文件夹
LitJson.dll
56KB
22.66KB
文件大小:
评论区