use false option with json decode to get an object
$j='{"error":"0","errorString":"","reply":{"nonce":"5e4155ca5f720","realm":"VMS"}}'; $nonce=json_decode($j,false)->reply->nonce;
// "5e4155ca5f720"
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
So i am trying to get values of json object from a url, when i hit that url using the GET method on postman i get something like this
{
"error": "0",
"errorString": "",
"reply": {
"nonce": "5e415334832a8",
"realm": "VMS"
}
}
So, i am trying to write a php code that displays the value of nonce in the browser but it is not working i have the following code
$getNonceUrl = "https://example.com/api/getNonce";
$getContect = file_get_contents($getNonceUrl);
$jsonNoce = json_decode($getContect, true);
$dd = $jsonNoce->reply[0]->nonce;
echo $dd;
I also did this
$ch = curl_init("https://193.178.55.230:3389/api/getNonce");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
echo $ch->reply[0]->nonce;
But it does not seem to work still.
Have you authorize https url?
https://stackoverflow.com/questions/1975461/how-to-get-file-get-contents-to-work-with-https
Please or to participate in this conversation.