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博客

相关推荐
小高Baby@2 小时前
JSON、bind、form
数据结构·json
2301_818732063 小时前
项目启动报错,错误指向xml 已解决
xml·java·数据库·后端·springboot
阿蒙Amon4 小时前
TypeScript学习-第11章:配置文件(tsconfig.json)
学习·typescript·json
一起养小猫8 小时前
Flutter for OpenHarmony 进阶:Timer组件与倒计时系统深度解析
android·网络·笔记·flutter·json·harmonyos
女王大人万岁10 小时前
Go语言JSON标准库(encoding/json):功能解析与实战指南
服务器·开发语言·后端·golang·json
csdn2015_1 天前
generatorConfig.xml 配置 Controller、Service 完整教程
xml·mybatis
每天要多喝水1 天前
nlohmann/json 的使用
c++·json
电商API&Tina1 天前
乐天平台 (Rakuten) 数据采集指南
大数据·开发语言·数据库·oracle·json
特立独行的猫a1 天前
从XML到Compose的UI变革:现代(2026)Android开发指南
android·xml·ui·compose·jetpack
spencer_tseng2 天前
Stream not available [SysDictDataMapper.xml]
xml·java