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

相关推荐
麻瓜code18 小时前
流式返回的工具参数是一段一段来的,怎么拼成一个 JSON
json
鲸渔3 天前
【AI Agent系列课程13-Python 基础13】JSON 读写:结构化数据交换基础
开发语言·python·json·ai编程
aiotto资源分享6 天前
Python 写 JSON 文件,程序中途退出会留下什么?
java·python·json·jsondecodeerror
一起学安全技术6 天前
拆大模型 10|结构化输出:让模型返回数据,而不是一段话
人工智能·语言模型·json
用户298698530147 天前
在 Python 中把 Word 文档转换为 JSON 的三种实现方式
python·json·api
FRing039 天前
vue2干货总结10(json-server、vant-ui、postcss插件、axios二次封装、图形验证码、toast轻提示)
开发语言·前端·vue.js·ui·json·vue2·postcss
用户298698530149 天前
使用 Python 将 JSON 转换为 Word 文档的实践指南
python·json·api
九英里路9 天前
protobuf快速上手
网络·c++·中间件·json·谷歌·序列化·protobuf
wuyk55510 天前
Spider-第09讲-三格式落盘CSV-Excel-JSON
爬虫·python·json·excel
wuyk55511 天前
Spider-第07讲-JSON接口与正则提取
爬虫·python·json