stdClass Object对象转换为数组

时间:2024-04-14 13:20:23
	public function url($method,$url,$headers,$host)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_FAILONERROR, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HEADER, false);
        if (1 == strpos("$".$host, "https://"))
        {
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        }
        $res = json_decode(curl_exec($curl));//这里为返回信息
        print_r($res);
    }

从接口上接受了一个数据,用了json_decode解析了一下,打印了是stdClass Object对象:
stdClass Object对象转换为数组

json_decode有第二个参数:

当json_decode($a, true;   		//打印出来的是数组
当json_decode($a;	 		//打印出来的是stdClass Object对象

加上true后:
stdClass Object对象转换为数组