仅从 bitbucket api 响应中获取 json
Get only json from bitbucket api response
这是我的代码:
$curl1 = curl_init();
$url = "https://bitbucket.org/api/2.0/repositories/webesian/jobmarkt/pullrequests/";
curl_setopt($curl1, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
curl_setopt($curl1, CURLOPT_USERPWD, "***:***");
curl_setopt($curl1, CURLOPT_HEADER, true);
curl_setopt($curl1, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl1, CURLOPT_URL, $url);
curl_setopt($curl1, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($curl1);
我的问题是输出变量不仅仅是 json。里面还有别的废话。我怎样才能从响应中只提取 json?
您已将 CURLOPT_HEADER
设置为 true,因此它将输出 header 信息作为响应的一部分。
删除它或将其设置为 false 应该可以解决问题
这是我的代码:
$curl1 = curl_init();
$url = "https://bitbucket.org/api/2.0/repositories/webesian/jobmarkt/pullrequests/";
curl_setopt($curl1, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
curl_setopt($curl1, CURLOPT_USERPWD, "***:***");
curl_setopt($curl1, CURLOPT_HEADER, true);
curl_setopt($curl1, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl1, CURLOPT_URL, $url);
curl_setopt($curl1, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($curl1);
我的问题是输出变量不仅仅是 json。里面还有别的废话。我怎样才能从响应中只提取 json?
您已将 CURLOPT_HEADER
设置为 true,因此它将输出 header 信息作为响应的一部分。
删除它或将其设置为 false 应该可以解决问题