json 파일을 xml로 변환하려고합니다. 그래서 JSON 디렉토리가 스캔되어 도착한 파일이 xml로 변환되어 xml 디렉토리로 옮겨집니다.변형 된 JSON 문자열 (Perl)
하지만 json.pl 줄에서이 오류를 폐쇄 핸들의 $의 FH에
의 readline()을 얻고 29
잘못된 JSON 문자열, 문자로도 배열, 객체, 숫자, 문자열 또는 원자, json.pl 라인 34
json.pl
#!/usr/bin/perl
use strict;
use warnings;
use File::Copy;
binmode STDOUT, ":utf8";
use utf8;
use JSON;
use XML::Simple;
# Define input and output directories
my $indir = 'json';
my $outdir = 'xml';
# Read input directory
opendir DIR, $indir or die "Failed to open $indir";
my @files = readdir(DIR);
closedir DIR;
# Read input file in json format
for my $file (@files)
{
my $json;
{
local $/; #Enable 'slurp' mode
open my $fh, "<", "$indir/$file";
$json = <$fh>;
close $fh;
}
# Convert JSON format to perl structures
my $data = decode_json($json);
# Output as XML
open OUTPUT, '>', "$outdir/$file" or die "Can't create filehandle: $!";
select OUTPUT; $| = 1;
print "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
print XMLout($data);
print "\n" ;
close(OUTPUT);
unlink "$indir/$file";
}
example.js에서 ("문자열 (종료)"이전에) 0 오프셋
{
"Manager":
{
"Name" : "Mike",
"Age": 28,
"Hobbies": ["Music"]
},
"employees":
[
{
"Name" : "Helen",
"Age": 26,
"Hobbies": ["Movies", "Tennis"]
},
{
"Name" : "Rich",
"Age": 31,
"Hobbies": ["Football"]
}
]
}
오류를 처리하려면'decode_json' 주위에'eval'을 넣는 것이 좋습니까? 'decode_json' 오류가 발생합니다. –