1

ハードコーディングされたjson文字列をperlハッシュに変換できますが、完全なjsonファイルを後で何らかの方法で解析できるperlデータ構造に変換したい場合、次のエラーが発生します。json_vellai.pl 行 9 の文字オフセット 0 ("(end of string)" の前) に、配列、オブジェクト、数値、文字列、アトムのいずれでもない不正な形式の JSON 文字列

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

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

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

#$fileContents = do { local $/;<FH>};

@fileContents = <FH>;

#print @fileContents;

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

foreach $t (keys %$str)

{


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

}

これが私のコードの外観です..助けてください

4

1 に答える 1

2

リストが必要ないように見えますdecodeが、スカラー文字列が必要です。

ファイルを丸呑みすることができます:

undef $/;
$fileContents = <FH>;
于 2011-08-22T06:56:27.700 に答える