2017-03-01 80 views
0

我從json文件獲取數據並在網站上顯示它。由於某種原因,它不顯示該ID。請指導。ID未從JSON數據顯示

function getJSON() { 
    /** These are the lyrics to Hello Dolly */ 
$slices = json_decode(file_get_contents('http://pf.tradetracker.net/?aid=1&type=json&encoding=utf8&fid=251713&categoryType=2&additionalType=2&limit=1000',true)); 
if ($slices) { 
    foreach ($slices as $slice) { 
     $ID = $slice->products->ID; 
     echo $ID; 
    } 
} 
} 

回答

1

你的根元素是產品,所以使用:

foreach ($slices->products as $slice) { 
     $ID = $slice->ID; 
     echo $ID; 
    }