我有一个php文件接收$ _GET信息和$ _POST信息,对于$ _GET信息没问题,所以对于我收到此字符串的$ _POST信息:
[{"channel":"\/meta\/handshake","id":"10","minimumVersion":"1.0","supportedConnectionTypes":["websocket","long-polling"],"version":"1.0"}]
以[开始]结束。
所以我怎么读这个?谢谢你的帮助!
答案 0 :(得分:1)
首先解码像这样的json
数据
$arr = json_decode($_POST,true);
然后访问这样的数据
echo $arr[0]['channel']; // output "/meta/handshake"
答案 1 :(得分:1)
$channels = json_decode(file_get_contents('php://input')); // parse raw post
print_r($channels) // print structure of channels
答案 2 :(得分:0)
试试这个:
$str = '[{"channel":"\/meta\/handshake","id":"10","minimumVersion":"1.0","supportedConnectionTypes":["websocket","long-polling"],"version":"1.0"}]';
echo "<pre>";
$arra = json_decode($str,true);
print_r($arra);
/*Uncomment this for your out put*/
//echo "Required : ".echo $arra[0]['channel'];
输出:
Array
(
[0] => Array
(
[channel] => /meta/handshake
[id] => 10
[minimumVersion] => 1.0
[supportedConnectionTypes] => Array
(
[0] => websocket
[1] => long-polling
)
[version] => 1.0
)
)