我想转换我创建的哈希数组,如下所示:
while(...)
{
...
push(@ranks, {id => $id, time => $time});
}
到 JSON:
use JSON;
$j = new JSON;
print $j->encode_json({ranks => @ranks});
但它正在输出:
{"ranks":{"time":"3","id":"tiago"},
"HASH(0x905bf70)":{"time":"10","id":"bla"}}
如您所见,它无法写入哈希并且没有数组...
我想输出一个如下所示的 JSON 字符串:
{"ranks":[{"time":"3","id":"tiago"},
{"time":"40","id":"fhddhf"},
{"time":"10","id":"bla"}]}