Perl-181006-xml 转 json

版权声明:欢迎转载,并请引用链接。 https://blog.csdn.net/u012251305/article/details/82950580

Problem

Perl 实现 xml 转 json

Solution

#!/usr/bin/perl -w

use XML::Simple;
use Encode;
use JSON;
# use Data::Dumper;
# print Dumper (XML::Simple->new()->XMLin($ARGV[0]));

$xml = new XML::Simple;
my $data = $xml->XMLin($ARGV[0]);
# print "\$data\n";

my $a = $data->{"a"};
my $b = $data->{"b"};
my %hash = (
	'a' => $a,
	'b' => $b);

my $json_data = encode_json \%hash;
print "$json_data\n";

Reference

  1. perl 解析xml ,json文件及curl工具的使用
  2. How to convert a simple hash to json in Perl?

猜你喜欢

转载自blog.csdn.net/u012251305/article/details/82950580
今日推荐