I'm trying to decode a json obtening by cURL with php like this :
$url = 'https://www.toto.com/api/v1/ads/?apikey=titi&code_postal='.$code_postal.'&type_de_bois='.$type_bois; $cURL = curl_init(); curl_setopt($cURL, CURLOPT_URL, $url); curl_setopt($cURL, CURLOPT_HTTPGET, true); curl_setopt($cURL, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Accept: application/json' )); $result = curl_exec($cURL); curl_close($cURL); var_dump(json_decode($result, true)); echo json_decode($result); That returns me that, something which seems to be json :
[{"id":"6918","nom":"X","code_postal":"88120","ville":"town","description":"test","logo":"test.png","url":"test","telephone":true}, [{"id":"6919","nom":"Y","code_postal":"88121","ville":"town1","description":"test","logo":"test.png","url":"test","telephone":true}, [{"id":"6920","nom":"Z","code_postal":"88122","ville":"town2","description":"test","logo":"test.png","url":"test","telephone":true}]
int(1) 1
My question are : - Why, without echo or print, the array is printed? - Why json_decode doesn't work propely or why it is only one value ("1")?
Thanks a lot for your answer.