dongyou6768 2018-09-26 18:47
浏览 38

如何将JSON数据解码为php,而数据格式就像{“1”:Data1,“2nd”:Data2}

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作