我有这个JSON字符串如何将此字符串编码为JSON?
$json_string = qq{{"error" : "User $user doesn't exist."}};
这是我在一个较低水平的方式构建,可以这么说。
如何使用JSON模块对其进行编码?
现在我编码这样
use JSON;
my $json_string;
my $json = JSON->new;
$json = $json->utf8;
my $data;
$data->{users} = $json->encode(\%user_result);
$data->{owners} = $json->encode(\%owner_result);
$json_string = to_json($data);
print $cgi->header(-type => "application/json", -charset => "utf-8");
print $json_string;
你为什么双编码的JSON? – cjm 2011-05-25 10:18:32