PHP JSON响应以字符串值开头

时间:2019-02-22 10:41:41

标签: php json

我有一些非常简单的代码,它看起来可以使用CURL查询API并返回json响应。

代码如下:

select count(*),count(country) from table group by country having count(country)>1

以下是回复:

<?php

...[VARIABLES]...

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$result = curl_exec($ch);
var_dump($result);

?>

我正在努力理解为什么在JSON响应的前面显示字符串(310),因为我只期望JSON响应。

1 个答案:

答案 0 :(得分:1)

使用echo打印响应

<?php

    ...[VARIABLES]...

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_PROXY, $proxy);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    $result = curl_exec($ch);
    echo $result;

    ?>