Giter VIP home page Giter VIP logo

js-xmltojson's Introduction

XML 转为 JSON

在我们日常开发当中可能会有 XML 数据交互需求, 这时候处理某个节点就比较麻烦, 然后自己动手封装了一下, 嘻嘻,多的不说 ,直接上代码~

1.使用

<script src="src/js/xmlToJson.min.js"></script>
//待转换的xml字符串
let xmlText = `
    <userInfo version="1.0.0">
        <token>12366666666</token>
        <isAdmin>true</isAdmin>
        <account>admin</account>
        <userName>管理员</userName>
        <id>12345678</id>
        <mobile>13928281818</mobile>
        <alias>猛追湾彭于晏</alias>
        <roles>
            <role id="123456" name="超级管理员"></role>
            <role id="12345" name="管理员"></role>
        </roles>
        <orgs>
            <org id="123456" name="四川移动"></org>
            <org id="12345" name="成都移动分公司"></org>
        </orgs>
    </userInfo>
`;

let jsonData = XmlToJson.parse(xmlText, {
    textKey: 'value',
    conversionkeyMap: {
        userInfo: 'userData',
        roles: 'userRoles'
    }
}); //转换后的JSON数据
console.log(jsonData);

2.参数说明

参数名 类型 是否必填(Y/N) 描述
xmlString String Y xml字符串
conf Object N 配置信息
conf.textKey String N 属性text值
conf.jsonString Boolean N json字符串
conf.conversionkeyMap Object N 替换数据Key(深度)

更多功能正在更新中...

js-xmltojson's People

Stargazers

slm avatar dylan avatar  avatar  avatar  rookie_fly avatar

Watchers

打杂的Haor呀 avatar

Forkers

miui8824

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.