a website as https://api.site.tld/myvalue returns a JSON object:
{
"alpha": "first",
"beta": "second",
"charlie": "third"
}
This code returns instead "Trying to get property 'beta' of non-object..."
$org = "https://api.site.tld/$mvalue";
$character = json_decode($org);
echo $character->beta;
Where I wrong? Thanks!
You need to retrieve the content of the webpage first. Then you can decode it :
$org = "https://api.site.tld/$mvalue";
$content = file_get_contents($org);
$character = json_decode($content);
echo $character->beta;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.