我想轉換散列的數組,我創造這樣的:哈希轉換陣列JSON
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"}]}
什麼是$ J′你用什麼軟件包來支持JSON? – schtever
對不起,更新了這個問題... –