I am trying to fetch data from third-party API using curl in PHP. Here it is my code and I want to fetch response in the object. Here I got in string
$ch = curl_init();
curl_setopt_array($ch,
array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData
));
//Ignore SSL certificate verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//get response
$output = curl_exec($ch);
//Print error if any
if(curl_errno($ch))
{
echo 'error:' . curl_error($ch);
}
curl_close($ch);
echo $output;
echo gettype($output);
The response of echo $output is like
{"access_token": "", "expires_in": xxxx, "token_type": "", "scope": ""}
and another response for echo gettype($output) is print like
string
but i want into object/array from the curl_response or else i want to convert this string $output into object/array.
json_decodefunction in PHP