我正在生成Json字符串,它不会生成良好的Json。对我来说,它看起来很好,但我有一个错误somwhere。我找不到它在哪里以及如何删除它。 这里是整个来源(因为它很短)。生成json解析错误
use strict;
use warnings;
use JSON qw(decode_json);
sub getJsonStr{
print "Enter the name of the person: ";
my $name = <>;
print "Enter the age of the person: ";
my $age = <>;
my $json = '{
"name" :"'.$name.'",
"age" :"'.$age.'"
}';
}
my $jsonStr = getJsonStr();
print $jsonStr;
my $jobj = decode_json($jsonStr);
' '{ “名称”: “'。$名字。 '” ......''好写为'Q({ “名”: “$名” ...)' – TLP
@TLP ... 'qq({“name”:“$ name”,...})'为了'$ name'插入(不仅仅是'q(...)')。 – amon
@amon当然,我在那里脑残。尽管我现在要说的是使用Quentin的解决方案。 – TLP