簡體   English   中英

如何從URL獲取PHP中的JSON輸出

[英]How to get json output in php from url

我看到有關此的更多問題,但對我沒有用。

我在這里有鏈接,下面的代碼是我的鏈接

<?php 
$json=file_get_contents("http://2strok.com/radio.json");
$details=json_decode($json);
if($details->Response=='True')
?>

<?php echo $details->name[3];?><br>
$json=file_get_contents("http://2strok.com/radio.json");
$details=json_decode($json,true);
foreach($details as $output) {
    echo $output['name'].'<br>';
}

更新-獲取特定名稱

$json=file_get_contents("http://2strok.com/radio.json");
$details=json_decode($json,true);
foreach($details as $output) {
    if ($output['name']=='FM 101 / Islamabad'){
        echo 'Specific name found: '.$output['name'];
    }
    // echo $output['name'].'<br>';
}

json解碼后,它返回一個對象數組,因此請嘗試以下操作:

$json=file_get_contents("http://2strok.com/radio.json");
$details=json_decode($json);

foreach ($details as $detail){
    echo $detail->name;
    echo "<br>";
} 
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM