开发者

I am converting a json file returned from the server into perl data structures

I am able to convert a hard coded json string into perl hashes however if i want to convert a complete json file into perl data structures which can be parsed later in any manner, I am getting the folloring error. malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "(end of string)") at json_vellai.pl line 9

use JSON::PP;
$json= JSON::PP->new()

$json = $json->allow_singlequote([$enable]);

open (FH, "jsonsample.doc") or die "could not open the file\n";

#开发者_StackOverflow$fileContents = do { local $/;<FH>};

@fileContents = <FH>;

#print @fileContents;

$str = $json->allow_barekey->decode(@filecontents);

foreach $t (keys %$str)

{


print "\n $t -- $str->{$t}";

}

This is how my code looks .. plz help me out


It looks to me like decode doesn't want a list, it wants a scalar string.

You could slurp the file:

undef $/;
$fileContents = <FH>;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜