Unity XML和Json文件的读取和写入以及序列化和反序列化

xml文件的生成

cs 复制代码
 void CreateXml()
 {
     string path = Application.streamingAssetsPath + "/testXml.xml";
     Debug.Log(path);

     //创建
     XmlDocument xml = new XmlDocument();
     //创建最上一层的节点。
     XmlElement root = xml.CreateElement("root");
     //创建子节点
     foreach (var item in ColorFunctionDBModel.Instance.GetList())
     {
         Debug.Log(item.id);
         XmlElement element = xml.CreateElement("table");
         element.SetAttribute("id", item.id);
         element.SetAttribute("display", item.display);
         element.SetAttribute("english", item.english);
         element.SetAttribute("hex", item.hex);
         element.SetAttribute("fun", item.fun);
         element.SetAttribute("enable", item.enable);
         root.AppendChild(element);
         xml.AppendChild(root);
     }

     //把节点一层一层的添加至xml中,注意他们之间的先后顺序,这是生成XML文件的顺序
     //最后保存文件
     xml.Save(path);
 }

参考:

Unity序列化之XML,JSON--------合成与解析:pc端_unity 将数据结构序列成xml-CSDN博客

相关推荐
码农学院10 小时前
JSON 里是一个空字符串 ““,Newtonsoft.Json 无法直接把字符串转成列表
json
c1s2d3n4cs1 天前
Qt模仿nlohmann::json进行序列化和反序列化
开发语言·qt·json
一只很酸de橘子1 天前
PostgreSQL 生成 JSON 字符串
postgresql·json
Kiyra1 天前
Query Rewrite 不是越智能越好:RAG 检索的精确词保护与动态召回
redis·websocket·junit·单元测试·json
Msshu1231 天前
XSP25全协议 100W PD快充诱骗芯片_串口读电压电流信息
hive·云计算·json·database·memcached
水火既济__1 天前
hive中加载json数据建表(大规模)
hive·hadoop·json
朝新_1 天前
【LangChain】输出解析器 Str/Pydantic/JSON 解析器用法详解 告别模型乱输出
microsoft·langchain·json
鹏晨互联1 天前
Jetpack Compose vs XML:fillMaxSize、fillMaxHeight、fillMaxWidth 全面对比
android·xml
Kiyra2 天前
LLM 的 JSON 不靠谱:结构化输出的重试与修复实战
开发语言·python·json