Search code examples
phpjsonresponse

PHP Decode JSON variables


I have the following json file below that outputs the following information:

stdClass Object
(
[status] => OK
[droplet] => stdClass Object
    (
        [id] => 567894
        [name] => Luna
        [created_at] => 2013-10-10T18:13:08Z

    )

)

I'm trying to get the [name] and save it to a variable called $serverName. I've tried using the code below but have no luck :/

<?php
    $request = 'Link to JSON FILE';
    $response  = file_get_contents($request);
    $jsonobj  = json_decode($response);

    $serverName = $jsonobj->name;

I've tried looking online but I'm having troubles getting this to work :/

Thanks a ton <3


Solution

  • Got it to work. Just need to do;

    $jsonobj->droplet->name;