xml2json

功能描述

XML和JSON互相转换,用例见 xml2json_demo.html

依赖的插件

libs/xml2json.js
libs/json2xml.js

快速使用

引入 libs/xml2json.js

xml转json

var xmlObj = `
    <note>
      <to>Tove</to>
      <from>Jani</from>
      <heading>Reminder</heading>
      <body>Don't forget me this weekend!</body>
    </note>
`;
// 第二个参数可格式化返回的数据显示在页面/控制器
console.log(xml2json(xmlObj, "  "));

json转xml

引入 libs/json2xml.js

var jsonObj = `
    {
      "note":  {
        "to":"Tove",
        "from":"Jani",
        "heading":"Reminder",
        "body":"Don't forget me this weekend!"
      }
    }
`;
// 第二个参数可格式化返回的数据显示在页面/控制器
console.log(json2xml(jsonObj, "  "));
是否仍需要帮助? 请保持联络!
最后更新于 2024/04/24