为什么这个PHP脚本是JSON结果,而我还没有';我没有告诉它


Why is this PHP script the JSON results when I haven't told it to?

所以我使用我找到的唯一一个向Google QPX API发送post请求的源。我想把它保存在json_edecoded的PHP数组中,但由于某种原因,$result = curl_exec($ch);行不起作用,json无论如何都会在屏幕上打印出来。

cURL中是否发生了我不理解的事情?谢谢

$data = array ( "request" => array(
            "passengers" => array( 
                    adultCount => 1
                        ),
                    "slice" => array( 
                            array(
                                origin => "BOS",
                                destination => "LAX",
                                date => "2015-09-09"),
                            array(
                                origin => "LAX",
                                destination => "BOS",
                                date => "2015-09-10"),
                            ),
                                solutions => "10"
                            ),
             );
$data_string = json_encode($data);
$ch = curl_init('https://www.googleapis.com/qpxExpress/v1/trips/search?key=MY-API-KEY');                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));                                                                                                                   
$result = curl_exec($ch);
curl_close($ch);

这:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);

CURLOPT_RETURNTRANSFER-TRUE将传输作为curl_exec()的返回值的字符串返回,而不是直接输出。

http://php.net/curl_setopt

如果要将结果保存在变量中,请将此选项设置为true