I want to decode this data into a php obj, but this is not working. If I run the code it gives nothing.
$Data = "{"3":false,"5":false,"6":true}"
$obj = json_decode($Data, true);
echo $obj["3"];
echo $obj["5"];
Look at the below code.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://demo.thingsboard.io:443/api/plugins/rpc/twoway/67cadda0-b8c0-11e8-a04e-eb5f6cd0fada");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"method\": \"setGpioStatus\", \"params\": {\"pin\": \"".$PIN_NUMBER."\", \"enabled\": \"".$PIN_STATUS."\"}, \"timeout\": \"500\"}");
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "Accept: */*";
$headers[] = "X-Authorization: Bearer ".$New_JWT_TOKEN."";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$GPIO_RESULT = curl_exec($ch); // curl_exec($ch) gives {"3":false,"5":false,"6":true}
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
$obj = json_decode($GPIO_RESULT, true);
echo $obj["3"]; // output: null
echo $GPIO_RESULT; // output: {"3":false,"5":false,"6":true}
}
Now I get the output of $GPIO_RESULT
but not the output of $obj["3"]
or any single digit integer. I found that no integer value is accepted at this format. Can anyone tell me any other way to converting this data.