Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中从GET cURL获取JSON对象_Php_Json_Curl_Get - Fatal编程技术网

在php中从GET cURL获取JSON对象

在php中从GET cURL获取JSON对象,php,json,curl,get,Php,Json,Curl,Get,这是我的密码: $ch = curl_init(''); $request = 'where={"place":"'.$place.'"}&count=1&limit=0'; $url = "https://api.parse.com/1/classes/className" . "?" . $request; curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_HTTPHEADE

这是我的密码:

$ch = curl_init('');  

  $request = 'where={"place":"'.$place.'"}&count=1&limit=0';
  $url = "https://api.parse.com/1/classes/className" . "?" . $request;

  curl_setopt($ch, CURLOPT_URL,$url);



  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'X-Parse-Application-Id: ...',
    'X-Parse-REST-API-Key: ...
    ));

  //curl_setopt($ch, CURLOPT_POST, true);


  // Execute
  $result = curl_exec($ch);

  // Close connection
  curl_close($ch);
以下是输出:

{"results":[],"count":0}
我只想数到他的号码

我试过这个:

$json_res = json_decode($result, true);

  echo 'Number : '.$json_res['count'];
但结果是:

Number :
如果我使用
json\u encode
的话,结果就是一个
True

我试着添加了以下内容:

  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
但没有改变任何事情

我错过了什么

编辑:在$json\u res上执行var\u转储会得到:
int(1)

为什么会这样?

如果不设置CURLOPT\u RETURNTRANSFER选项,Curl不会返回输出

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

您是否费心检查json_decode()是否真的成功了?失败时返回一个php
null
。@MarcB-hmm,如何检查?如果($json_res==null){die(json_last_error());},则执行$json_res
的var_转储。当然,如果确实发送了一个有效的“null”值作为json字符串,这可能会产生误报。@AlexBarroso它会打印int(1)。