嗨,请帮我用perl从Hikvision扫描中获取AcsEvent。现在数据返回是。
{
"AcsEvent": {
"searchID": "1",
"responseStatusStrg": "MORE",
"numOfMatches": 5,
"totalMatches": 13430,
"InfoList": [
{
"major": 2,
"minor": 1024,
"time": "2021-12-02T10:45:33+07:00",
"netUser": "",
"remoteHostAddr": "0.0.0.0",
"cardNo": "",
"cardType": 0,
"name": "",
"reportChannel": 0,
"cardReaderKind": 0,
"cardReaderNo": 0,
"doorNo": 0,
"verifyNo": 0,
"alarmInNo": 0,
"alarmOutNo": 0,
"caseSensorNo": 0,
"RS485No": 0,
"multiCardGroupNo": 0,
"deviceNo": 0,
"employeeNoString": "",
"InternetAccess": 0,
"type": 0,
"MACAddr": "",
"swipeCardType": 0,
"serialNo": 1,
"userType": "normal",
"currentVerifyMode": "invalid",
"attendanceStatus": "undefined",
"statusValue": 0,
"mask": "unknown"
},
{
"major": 5,
"minor": 22,
"time": "2021-12-02T10:45:33+07:00",
"netUser": "",
"remoteHostAddr": "0.0.0.0",
"cardNo": "",
"cardType": 0,
"name": "",
"reportChannel": 0,
"cardReaderKind": 0,
"cardReaderNo": 0,
"doorNo": 1,
"verifyNo": 0,
"alarmInNo": 0,
"alarmOutNo": 0,
"caseSensorNo": 0,
"RS485No": 0,
"multiCardGroupNo": 0,
"deviceNo": 0,
"employeeNoString": "",
"InternetAccess": 0,
"type": 0,
"MACAddr": "",
"swipeCardType": 0,
"serialNo": 2,
"userType": "normal",
"currentVerifyMode": "invalid",
"attendanceStatus": "undefined",
"statusValue": 0,
"mask": "unknown"
},
{
"major": 5,
"minor": 75,
"time": "2021-12-02T10:53:49+07:00",
"netUser": "",
"remoteHostAddr": "0.0.0.0",
"cardNo": "",
"cardType": 1,
"name": "user1",
"reportChannel": 0,
"cardReaderKind": 0,
"cardReaderNo": 1,
"doorNo": 1,
"verifyNo": 0,
"alarmInNo": 0,
"alarmOutNo": 0,
"caseSensorNo": 0,
"RS485No": 0,
"multiCardGroupNo": 0,
"deviceNo": 0,
"employeeNoString": "1",
"InternetAccess": 0,
"type": 0,
"MACAddr": "",
"swipeCardType": 0,
"serialNo": 3,
"userType": "normal",
"currentVerifyMode": "cardOrFaceOrFp",
"attendanceStatus": "undefined",
"statusValue": 0,
"mask": "no",
"pictureURL": "http://192.168.1.11:8/LOCALS/pic/acsLinkCap/202112_00/02_105349_30075_0.jpeg@WEB000000000619",
"picturesNumber": 1
},
{
"major": 5,
"minor": 21,
"time": "2021-12-02T10:53:49+07:00",
"netUser": "",
"remoteHostAddr": "0.0.0.0",
"cardNo": "",
"cardType": 0,
"name": "",
"reportChannel": 0,
"cardReaderKind": 0,
"cardReaderNo": 0,
"doorNo": 1,
"verifyNo": 0,
"alarmInNo": 0,
"alarmOutNo": 0,
"caseSensorNo": 0,
"RS485No": 0,
"multiCardGroupNo": 0,
"deviceNo": 0,
"employeeNoString": "",
"InternetAccess": 0,
"type": 0,
"MACAddr": "",
"swipeCardType": 0,
"serialNo": 4,
"userType": "normal",
"currentVerifyMode": "invalid",
"attendanceStatus": "undefined",
"statusValue": 0,
"mask": "unknown"
},
{
"major": 5,
"minor": 75,
"time": "2021-12-02T10:53:52+07:00",
"netUser": "",
"remoteHostAddr": "0.0.0.0",
"cardNo": "",
"cardType": 1,
"name": "user1",
"reportChannel": 0,
"cardReaderKind": 0,
"cardReaderNo": 1,
"doorNo": 1,
"verifyNo": 0,
"alarmInNo": 0,
"alarmOutNo": 0,
"caseSensorNo": 0,
"RS485No": 0,
"multiCardGroupNo": 0,
"deviceNo": 0,
"employeeNoString": "1",
"InternetAccess": 0,
"type": 0,
"MACAddr": "",
"swipeCardType": 0,
"serialNo": 5,
"userType": "normal",
"currentVerifyMode": "cardOrFaceOrFp",
"attendanceStatus": "undefined",
"statusValue": 0,
"mask": "no",
"pictureURL": "http://192.168.1.11:8/LOCALS/pic/acsLinkCap/202112_00/02_105352_30075_0.jpeg@WEB000000000620",
"picturesNumber": 1
}
]
}
}我需要时间,名字,cardNo,pictureURL
结果就是这样。
2021-12-02T10:45:33+07:00null 2021-12-02T10:45:33+07:00null 2021-12-02T10:53:52+07:00 NULL user1 0.jpeg@WEB000000000619 2021-12-02T10:53:49+07:00 NULL 2021-12-02T10:53:52+07:00 NULL user1 0.jpeg@WEB000000000620
我能做什么。谢谢
编辑:我可以通过戴夫·克罗斯修复它。这是我的密码。
#!/bin/perl
use JSON;
use feature qw(say);
use strict;
use warnings;
my $json = '{
"AcsEvent": {
"searchID": "1",
"responseStatusStrg": "MORE",
"numOfMatches": 5,
"totalMatches": 13430,
"InfoList": [
{
....cut off data ......
}
]
}
}';
my $data = JSON->new->decode($json);
my @infolist = @{ $data->{AcsEvent}{InfoList} };
for my $item (@infolist) {
say $item->{time};
say $item->{cardNo};
say $item->{name};
say $item->{pictureURL};
}发布于 2022-01-24 11:31:36
因此,您有一个包含JSON编码的数据结构的文本字符串。要做的第一件事是将其转换为Perl数据结构。我们可以使用JSON模块来完成这个任务。
use JSON;
# Assuming that you've got your JSON text in $json
my $data = JSON->new->decode($json);您的$data变量现在包含一个哈希引用。您可以看出它将是一个散列引用,因为JSON文本是由{ ... }括起来的。
您希望使用JSON的InfoList部分。我们可以通过在数据结构中查找几个键来实现这一点。
my @infolist = @{ $data->{AcsEvent}{InfoList} };注意,$data->{AcsEvent}{InfoList}是一个数组引用(我们可以判断,因为它是由[ ... ]封装的)。因此,我们可以取消引用,并将其存储在数组变量(@infolist)中。
现在,这只是一个遍历新数组的例子。数组的每个元素都是一个散列引用,因此我们可以非常简单地提取我们想要的信息。
for my $item (@infolist) {
say $item->{time};
}其余的输出将留作读者练习使用。
https://stackoverflow.com/questions/70825974
复制相似问题