How can I extract the value of this json in php?

£可爱£侵袭症+ 提交于 2019-12-13 03:59:50

问题


I would like to know, how take the value "Tile32px" from this Json: (http://360api.chary.us/?gamertag=superdeder) with PHP.

I tried this way:

<?php    
$json = file_get_contents('http://360api.chary.us/?gamertag=superdeder');
$gamer = json_decode($json);
echo $gamer->Gamertag;
echo "<br><br>";  

$data = json_decode($json, true);

$users=$data['LastPlayed'];
foreach ($users as $user)
    {
     echo $user['Title'];
     echo "<br>";
    }
echo "<br>";        
$users2=$data['Pictures'];
foreach ($users2 as $user2)
{
     echo $user2['Tile32px'];
     echo "<br>";
}       
?>

This is the result:

SuperDeder

Skyrim Grand Theft Auto V FIFA 13 L.A. Noire WSOP: Full House Pro

h h h

Thanks a lot.
Andrea.


回答1:


Try this way.

<?php

$json = file_get_contents('http://360api.chary.us/?gamertag=superdeder');


$data = json_decode($json, true);


foreach ($data['LastPlayed'] as $val)
    {
     echo $val['Pictures']['Tile32px'];
     echo "<br>";
    }   

?>



回答2:


Try this

<?php
    $json = file_get_contents('http://360api.chary.us/?gamertag=superdeder');
    $gamer = json_decode($json, true);
    $users = $gamer['LastPlayed'];
    foreach($users as $user){
    echo $user['Pictures']['Tile32px'];
    echo '<br>';
    }
?>


来源:https://stackoverflow.com/questions/26606514/how-can-i-extract-the-value-of-this-json-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!