2014-10-28 12 views
0

我想知道,如何从这个Json采用值“Tile32px”: (http://360api.chary.us/?gamertag=superdeder)与PHP。如何在php中提取此json的值?

我试着这样说:

<?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>"; 
}  
?> 

这是结果:

SuperDeder

天际 侠盗猎车手V FIFA 13 黑色洛城 WSOP:浪漫满屋临

h h h

非常感谢。
Andrea。

+1

'的var_dump($玩家)'PS:你为什么'json_decode'两次? – zerkms 2014-10-28 10:57:33

回答

0

试试这个方法。

<?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>"; 
    } 

?> 
1

试试这个

<?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>'; 
    } 
?>