This article mainly introduces the method of php curl to obtain json objects and convert them into arrays. It has certain reference value. Now I share it with you. Friends in need can refer to it
Example:
function objtoarr($obj){ $ret = array(); foreach($obj as $key =>$value){ if(gettype($value) == 'array' || gettype($value) == 'object'){ $ret[$key] = objtoarr($value); }else{ $ret[$key] = $value; } } return $ret; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'http://www.tudou.com/albumcover/albumdata/getAlbumItems.html?acode=pEFBZGfERLo&charset=utf-8'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_ENCODING, "gzip"); $output = curl_exec($ch); curl_close($ch); $content = json_decode($output); $content_arr = objtoarr($content); var_dump($content_arr);
The above is the entire content of this article, thank you for reading. Please pay attention to the PHP Chinese website for more information!
Related recommendations:
php curl simulates login and obtains data instance
php curl batch processing to achieve controllable concurrent asynchronous operation case details
The above is the detailed content of How to use php curl to obtain a json object and convert it into an array. For more information, please follow other related articles on the PHP Chinese website!