zhumao

新手上路

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

#!/usr/bin/perl

use strict;
use JSON::Any;
use XML::Simple;

my $json = '{"name":"zhumao","pass":"123","other":[{"a0":"a0a0a0","b0":"b0b0b0"},{"a1":"a1a1a1","b1":"b1b1b1"}]}';

$json=~s/[\x00-\x1f]//g;#过滤不可见字符
my $convertor = JSON::Any->new();
my $data = $convertor->decode($json);
my $xml = XMLout($data);#生成xml

open(O,">:utf8","test.xml");#将xml写入文件(如果有中文,需要加:utf8)
print O qq#<?xml version="1.0" encoding="UTF-8"?>\n#;
print O $xml;
close(O);

注:不要使用JSON2XML,很难用。

posted on 2018-10-02 18:52  zhumao-2  阅读(325)  评论(0编辑  收藏  举报