如何将curl获取到的json对象转成数组
如何将curl获取到的json对象转成数组?
今天为大家分享一篇php curl获取到json对象并转成数组array的方法,具有很好的参考价值,希望对大家有所帮助。
例子:
- 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);