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 stm32代码移植没反应
    • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
    • ¥100 连续两帧图像高速减法
    • ¥15 组策略中的计算机配置策略无法下发
    • ¥15 如何绘制动力学系统的相图
    • ¥15 对接wps接口实现获取元数据
    • ¥20 给自己本科IT专业毕业的妹m找个实习工作
    • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
    • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
    • ¥50 mac mini外接显示器 画质字体模糊