Martin
Martin

Reputation: 73

json_decode file_get_contents help

<?php
$json = file_get_contents('http://tiny.cc/ttrhelp');

$obj = json_decode($json);
$example = $obj->rooms->displayName;
?>

Name: <?php echo $example; ?>

Trying to show the value for 'displayName' but its not showing

Upvotes: 2

Views: 23654

Answers (4)

stealthyninja
stealthyninja

Reputation: 10371

Try

echo $obj->rooms[0]->displayName;

Upvotes: 2

Tudor Constantin
Tudor Constantin

Reputation: 26861

Untested code:

<?php
$json = file_get_contents('http://pub.tapulous.com/tapplications/coresocial/v1/chat/api/index.php?method=room_list');

$obj = json_decode($json);
foreach($obj->rooms as $room){
    $example = $room->displayName;
    echo $example;
}

?>

Upvotes: 10

Quamis
Quamis

Reputation: 11087

echo $obj->rooms[2]->displayName;

Upvotes: 2

alex
alex

Reputation: 490303

You probably want $obj->rooms[0]->displayName.

CodePad.

Upvotes: 5

Related Questions