I’d like to get the value (v) of Power in the AC section of this JSON file with a PHP script.
{
"inverters": [
{
"serial": "xxxxxxxxxxx",
"name": "Block1",
"order": 0,
"data_age": 2,
"poll_enabled": true,
"reachable": true,
"producing": true,
"AC": {
"0": {
"Power": {
"v": 666.2000122,
"u": "W",
"d": 1
},
"Voltage": {
"v": 240.1000061,
"u": "V",
"d": 1
},
"Current": {
"v": 2.769999981,
"u": "A",
"d": 2
},
"Frequency": {
"v": 50,
"u": "Hz",
"d": 2
},
"PowerFactor": {
"v": 0.949999988,
"u": "",
"d": 3
},
"ReactivePower": {
"v": 218.3999939,
"u": "var",
"d": 1
}
}
}, [...]
I was trying it with the following code that worked with a simpler structure but now fails:
$PowerV = round($jsonobj->inverters[0]->AC[0]->Power->v, 2, PHP_ROUND_HALF_UP);
then I asked the copilot and it came up the the following (working) alternative:
$PowerV = round($jsonobj['inverters'][0]['AC'][0]['Power']['v'], 2, PHP_ROUND_HALF_UP);
But I still like to understand what was wrong with the original code I tried.
Thanks for your help!