cmd
プロンプトを介して perl スクリプトを実行しようとすると、json
文字列が返されます。[]
他の投稿を読み、データベースを修正しましたがutf8
、エラーは引き続き発生します。perl文字列をエンコードする2つの異なる方法を試しましたが、最初は$json = encode_json @temp_array
このエラーを返す方法でしたがhash- or arrayref expected (not a simple scalar, use allow_nonref to allow this
、この行$json_text = $json->encode(@temp_array)
を使用すると[]
これが私のperlです:
my $json_text;
my $json = JSON->new->utf8;
my @temp_array =[];
my $temp_array;
while (@data = $query_handle->fetchrow_array())
{
my %json_hash = ();
my $hash_ref;
%json_hash = (
"User ID" => $data[0],
"Status" => $data[1],
"Last Password Reset" => $data[2],
"Reset Needed" => $data[3]
);
$hash_ref = \%json_hash;
push (@temp_array, $hash_ref);
}
print $json = encode_json @temp_array . "\n"; #encode with error
print $json_text = $json->encode(@temp_array) . "\n"; #encode with []
print $cgi->header(-type => "application/json", -charset => "utf-8");
print $json_text; #Prints []
したがって、私自身のテストではcmd prompt
、while がデータベースからデータを正しく取得し、ハッシュを作成していることを知っています。これは正しいと想定しています。
ハッシュ自体ではなく、ハッシュ参照を配列にプッシュしているという事実ですか? この文字列を正しく作成したら、それを html 経由で呼び出します。jquery
ありがとうございました。