PHP判断JSON数据类型

判断PHP变量数据变量

gettype($first) //$first为要判断的变量

返回类型
在这里插入图片描述

$DecryptMsg数据

{
    
    "DataList":[{
    
    "address":"测试门禁_80692","baseMacAddr":"xx:xx:xx:xx:xx:xx","checkTime":1611793083000,"corpId":"你自己的","groupId":"你自己的","bizId":"E6C151496AC6DF9FE68D6AEED5824667","locationMethod":"ATM","checkByUser":true,"deviceName":"测试门禁_80692","deviceSN":"xxxxxxxxxxxx","userId":"xxxxxxxxxxxx"}],"EventType":"attendance_check_record"}

$arrmsg= json_decode($DecryptMsg);  

$arrmsg->DataList为数组类型

$first = array_shift($arrmsg->DataList); //取第一个数组元素

$first为对象object

我的目的读取"locationMethod":“ATM”

$first->locationMethod

返回结果
ATM
结束

猜你喜欢

转载自blog.csdn.net/taogunet/article/details/113309121