我想用php发送数据,curl。我有以下代码与包含数据的字符串:
<?php
$string='
{
"unidad": [
{ "baterias": { "bat1": "10", "bat2": "18", "bat3": "13", "bat4": "18" } },
{ "lineas": { "line1": "110", "line2": "128", "line3": "130", "line4": "125" } },
{ "ampers": { "amp1": "10", "amp2": "7", "amp3": "13" }
}
]
}';
$jsonDataEncoded=json_encode($string,true);
$curl_connection = curl_init('http://172.27.17.210:81/recv_json.php');
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $jsonDataEncoded);
$result = curl_exec($curl_connection);
echo $result;
curl_close($curl_connection);
?>
我已经关注php文件来处理数据:
enter code here
<html>
<body>
<?php
$json_input_data=json_decode(file_get_contents('php://input'),TRUE);
echo gettype($json_input_data)."\n";
echo $json_input_data;
?>
</body>
</html>
结果是字符串,我想知道如何将字符串转换为数组,以便我可以访问其中包含的字段。
由于