參考 "PHP – Using oEmbed API to Embed Videos",想取回 JSON 資料,卻一直失敗。

研究了一下 PHP Manul,發現原因是文章裡說可以透過這樣的語法取值:

<?php
$decode = json_decode($json, true);
$thumb = $decode['thumbnail_url'];
?>

但實際上應該是這樣取值:

<?php
$decode = json_decode($json, true);
$thumb = $decode->{'thumbnail_url'};
?>

(不是中括號,而是大括號,並且要加上 "->"。)

arrow
arrow
    文章標籤
    oembed php
    全站熱搜

    小攻城師 發表在 痞客邦 留言(0) 人氣()