我無法用perl解析json對象,我不知道問題是來自json還是我的腳本。這裏是JSON:格式錯誤的JSON字符串,無論數組,對象,數字,字符串還是原子
test.json
{
"count":3,
"entries":
[
{
"id":85,
"application":AuditExampleLogin1,
"user":admin,
"time":"2011-11-22T10:29:37.422Z",
"values":
null
},
{
"id":87,
"application":AuditExampleLogin1,
"user":admin,
"time":"2011-11-22T10:30:56.235Z",
"values":
null
},
{
"id":89,
"application":AuditExampleLogin1,
"user":admin,
"time":"2011-11-22T10:33:15.000Z",
"values":
null
}
]
}
這裏的腳本:
script.pl
#!/usr/bin/perl -w
use strict;
use JSON;
open FILE, 'test.json' or die "Could not open file inputfile: $!";
sysread(FILE, my $result, -s FILE);
close FILE or die "Could not close file: $!";
my @json = @{decode_json($result)};
最後我得到的錯誤:
錯誤
malformed JSON string, neither array, object, number, string or atom,
at character offset 86 (before "AuditExampleLogin1,\n...") at
./script.pl line 7.
問:誰能告訴我該問題是否是由JSON或我的劇本,什麼未來在這兩種情況下的變化?
FYI json is coming from Alfresco auditing api。
AFAIK,這不是有效的JSON,周圍是否缺少值引號。 – Mat
我正在處理完全相同的問題。我對線程作者有一個問題:你如何訪問@json變量?我一直認爲@json是內存中的HASH,但我無法訪問變量或循環。 –