2013-02-09 2 views
0

안녕하세요 저는 CURL에서 약간 새로운 기능을 가지고 있지만 일부 json 데이터를 요청한 다음 결과를 구문 분석하려고합니다. 데이터 검색에 성공했지만 응답을 처리 할 수 ​​없습니다. 여기에 코드를Curl 응답의 json 데이터를 사용합니다.

function bitBucketCurl($url) 
{ 
global $bitPassword; 
global $bitUsername; 

$ch = curl_init(); 

// set URL and other appropriate options 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_USERPWD, "$bitUsername:$bitPassword"); 
curl_setopt($ch, CURLOPT_HEADER, 0); 

// grab URL and pass it to the browser 
$commitinfo = curl_exec($ch); 

// close cURL resource, and free up system resources 
curl_close($ch); 

return $commitinfo; 
} 

$json = bitBucketCurl($url); 
echo $json; // This seems to work in that, when I load the page, I can see the json data 

//turn json data into an array - this is what does not seem to be working 
$obj_a = json_decode($json, true); 

print_r ($obj_a); //the result is simply a 1 rather than the array I would expect 

을 기본 문제는 나는 그것이 작동하지 않는 배열에 데이터를 설정하려고 할 때 JSON 데이터가 때 echo $json하지만 보여줍니다입니다. 배열을 인쇄 할 때, 나는 '1'을 얻는다.

+0

그것을 보인다이 줄을 추가'curl_setopt ($ ch를, CURLOPT_RETURNTRANSFER, 1);'하지만 당신이 무엇을 설명 할 수 있다면 왜 그것이 중요합니다, 나는 행복하게 대답 크레딧을 부여합니다 :) – Jeff

+2

당신은 우리에게'$ json' 데이터를 보여줄 수 있습니까? – Peter

+0

'json_encode'의 두 번째 매개 변수는 상수 값을 허용하고 'true'는 거의 기대하지 않는 것입니다. [The docs] (http://php.net/json_encode)에서 사용할 수있는 상수를 확인하십시오. –

답변

1

내가받은 다음 줄을 추가하여 필요한 결과 : 잘

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);