• 技术文章 >后端开发 >php教程

    接收到的json解析不了,必须用php解析,该如何解决

    2016-06-13 12:31:11原创334
    接收到的json解析不了,必须用php解析

    function sendPost($url,$postData){
    $postdata = http_build_query($postData);
    $options = array(
    'http' => array(
    'method' => 'POST',
    'header' => 'Content-type:application/x-www-form-urlencoded',
    'content' => $postdata,
    'timeout' => 15 * 60 // 超时时间(单位:s)
    )
    );
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);

    return $result;
    }


    $url = "http://chepiao.sinaapp.com/api.php?act=remain";
    $data = array(
    "date"=>"20131220",
    "startStation"=>"北京",
    "arriveStation"=>"天津"
    );
    $result = sendPost($url, $data);
    $obj = json_decode($result);
    $result就是返回来的数据,就是解析不了,用json_decode($result);解析成的是NULL

    千万级数据并发解决方案

    相关文章推荐

    • 深入了解PHP反序列化原生类• 带你吃透16个PHP魔术方法• 浅析php变量作用域的一些问题_PHP• win7下memCache的安装过程(具体操作步骤)_PHP• PHP autoload与spl_autoload自动加载机制的深入理解_PHP
    1/1

    PHP中文网