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

相关推荐
华科易迅1 天前
Spring AOP(XML最终+环绕通知)
xml·java·spring
莫爷1 天前
JSON 进阶技巧:Schema 验证、JSONPath 查询、性能优化
性能优化·json
莫爷1 天前
JSON vs XML vs YAML 深度对比:如何选择合适的数据格式?
xml·前端·json
华科易迅1 天前
Spring AOP(XML后置+异常通知)
xml·java·spring
ZTLJQ1 天前
序列化的艺术:Python JSON处理完全解析
开发语言·python·json
CSharp精选营2 天前
.NET对象转JSON,到底有几种方式?
c#·json·.net·newtonsoft·对象转换·utf8json
淼_@淼2 天前
python-json
前端·python·json
Predestination王瀞潞2 天前
6.3.1 软件->W3C XPath 1.0 标准(W3C Recommendation):XPath(XML Path Language)查询语言
xml·数据库·oracle
Bear on Toilet2 天前
HTTP + JSON 接口调用清单总结
网络协议·http·json
萝卜白菜。2 天前
TongWeb7.0配置tongweb-web.xml修改jsessionid名及其值的长度
xml·前端·word