我有一个接收$_GET信息和$_POST信息的php文件,对于$_GET信息没有问题,所以对于$_POST信息我收到了这个字符串:
[{"channel":"\/meta\/handshake","id":"10","minimumVersion":"1.0","supportedConnectionTypes":["websocket","long-polling"],"version":"1.0"}]从开始到结束。
那么我该怎么读这个呢?感谢您的帮助!
发布于 2013-02-25 12:21:07
您可以使用json_decode` function
$channels = json_decode(file_get_contents('php://input')); // parse raw post
print_r($channels) // print structure of channels发布于 2013-02-25 12:16:34
首先对json数据进行如下解码
$arr = json_decode($_POST,true);然后像这样访问数据
echo $arr[0]['channel']; // output "/meta/handshake"工作示例http://codepad.viper-7.com/ZeI9n3
发布于 2013-02-25 12:24:31
试试这个:
$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
)
)参考:http://php.net/manual/en/function.json-decode.php
https://stackoverflow.com/questions/15059988
复制相似问题