【发布时间】:2014-04-24 12:15:07
【问题描述】:
我是从 xml 文件调用的,我基本上只是想将 xml 文件中的数据转换为 json,这就是我所拥有的
my $url ="someURL"
my $req = HTTP::Request->new(GET => $url);
$req->content_type('application/json');
my $json = new JSON;
my $request_json = $json->allow_blessed->encode($req);
$req->content($request_json);
my $lwp = LWP::UserAgent->new;
my $response = $lwp->request($req);
my $response_json = $response->content;
my $parsed = $json->allow_nonref->utf8->relaxed->decode($response_json);
最后一行给出以下响应:
malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "<mytag...")
【问题讨论】:
-
Re "我基本上只是想把 xml 文件中的数据转换成 json",你的代码中没有任何东西与 XML 有任何关系???
-
Re“我基本上只是想将 xml 文件中的数据转换为 json”。 JSON 创建了一个数据结构。您需要从构建正确的数据结构开始。您必须首先确定您拥有的 XML 的正确数据结构是什么。
-
为什么标记为
template-toolkit?someURL是 XML 文档吗?您为什么要尝试对HTTP::Request对象进行 JSON 编码?