<?php
$json = '{
"device" : [{
"id" : "18496597",
"clientDeviceId" : "18",
"name" : "Adven",
"state" : 1,
"statevalue" : "0",
"methods" : 3,
"type" : "device",
"client" : "2612195",
"online" : "1",
"editable" : 1,
"ignored" : 0
}, {
"id" : "18327685",
"clientDeviceId" : "7",
"name" : "Alla",
"state" : 1,
"statevalue" : null,
"methods" : 3,
"type" : "group",
"client" : "261295",
"online" : "1",
"editable" : 1,
"ignored" : 0
}
]
}';
$devices = json_decode($json);
var_dump($devices);
foreach ($devices->device as $device) {
echo $device->name . ' - '. $device->state . PHP_EOL;
}
echo json_last_error();
- Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
- object(stdClass)#3 (1) {
["device"]=>
array(2) {
[0]=>
object(stdClass)#1 (11) {
["id"]=>
string(8) "18496597"
["clientDeviceId"]=>
string(2) "18"
["name"]=>
string(5) "Adven"
["state"]=>
int(1)
["statevalue"]=>
string(1) "0"
["methods"]=>
int(3)
["type"]=>
string(6) "device"
["client"]=>
string(7) "2612195"
["online"]=>
string(1) "1"
["editable"]=>
int(1)
["ignored"]=>
int(0)
}
[1]=>
object(stdClass)#2 (11) {
["id"]=>
string(8) "18327685"
["clientDeviceId"]=>
string(1) "7"
["name"]=>
string(4) "Alla"
["state"]=>
int(1)
["statevalue"]=>
NULL
["methods"]=>
int(3)
["type"]=>
string(5) "group"
["client"]=>
string(6) "261295"
["online"]=>
string(1) "1"
["editable"]=>
int(1)
["ignored"]=>
int(0)
}
}
}
Adven - 1
Alla - 1
0
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
object(stdClass)#3 (1) {
["device"]=>
array(2) {
[0]=>
object(stdClass)#1 (11) {
["id"]=>
string(8) "18496597"
["clientDeviceId"]=>
string(2) "18"
["name"]=>
string(5) "Adven"
["state"]=>
int(1)
["statevalue"]=>
string(1) "0"
["methods"]=>
int(3)
["type"]=>
string(6) "device"
["client"]=>
string(7) "2612195"
["online"]=>
string(1) "1"
["editable"]=>
int(1)
["ignored"]=>
int(0)
}
[1]=>
object(stdClass)#2 (11) {
["id"]=>
string(8) "18327685"
["clientDeviceId"]=>
string(1) "7"
["name"]=>
string(4) "Alla"
["state"]=>
int(1)
["statevalue"]=>
NULL
["methods"]=>
int(3)
["type"]=>
string(5) "group"
["client"]=>
string(6) "261295"
["online"]=>
string(1) "1"
["editable"]=>
int(1)
["ignored"]=>
int(0)
}
}
}
Adven - 1
Alla - 1
0
preferences:
140.31 ms | 404 KiB | 185 Q