Perl-181006-xml 转 json

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?

你可能感兴趣的:(Perl,Linux,Perl,JSON,XML)