我用perl解析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,"time":"2011-11-22T10:30:56.235Z",{ "id":89,"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还是我的脚本以及在两种情况下要改变什么?
解决方法
如果引用了Audit …和admin值,它就可以工作.这条线
my @json = @{decode_json($result)};
需要是公正的
my @json = decode_json($result);