解析XML字符串为json对象

  var overtime='<?xml version="1.0" encoding="UTF-8"?><response><code><liuhao>5555555</liuhao><age>555555555</age></code> <message>success</message> <totalCount>5000000</totalCount> <remainCount>4999883</remainCount> <DonateCount>12</DonateCount> <Limit>80088800</Limit></response>';
    function  parseXMLsimple(target){
        var reg=/<([a-z,A-Z]+)>(.+)<\/\1>/g;
        var obj={};
        target.replace(reg,function(a,b,c){
            obj[b]=reg.test(c)?parseXMLsimple(c):c;
        })
        return obj;
    }
    console.log(parseXMLsimple(overtime))

  

posted @ 2017-07-26 15:09  刘浩2561179983  阅读(900)  评论(0编辑  收藏  举报