angular6 xml文件解析成json数据,json数据生成xml

1. 从后台读取xml数据,读取结果,话不多说,直接上代码 

    var kk = "<root><satellite>GF3</satellite><sensor>SAR</sensor><level>LEVEL1A</level><startTime>2017-01-20 11:02:34.571182</startTime><endTime>2017-01-20 11:02:43.420619</endTime><cloudPercent>0</cloudPercent><gsd>5</gsd><topLeftLat>34.977452</topLeftLat><topLeftLong>105.190206</topLeftLong><topRightLat>35.058405</topRightLat><topRightLong>105.773972</topRightLong><bottomRightLat>34.484358</bottomRightLat><bottomRightLong>105.890447</bottomRightLong><bottomLeftLat>34.403121</bottomLeftLat><bottomLeftLong>105.310854</bottomLeftLong></root>"

    xml2js.parseString(kk, function (err, result) {
      console.dir(result.root.bottomLeftLat[0]); // Prints JSON object!
    });

结果如下图:

 

2. 前端json数据转换成xml数据传到后台

 var mm = {
      root: {
        bottomLeftLat: ["34.403121"],
        bottomLeftLong: ["105.310854"],
        bottomRightLat: ["34.484358"],
        bottomRightLong: ["105.890447"],
        cloudPercent: ["0"],
        endTime: ["2017-01-20 11:02:43.420619"],
        gsd: ["5"],
        level: ["LEVEL1A"],
        satellite: ["GF3"],
        sensor: ["SAR"],
        startTime: ["2017-01-20 11:02:34.571182"],
        topLeftLat: ["34.977452"],
        topLeftLong: ["105.190206"],
        topRightLat: ["35.058405"],
        topRightLong: ["105.773972"]
      }
    }

    var outxml = builder.buildObject(mm).toString();

结果如下图所示:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wu_223

嘿嘿,求打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值