PHPでGoogle Dictionary API JSONレスポンスをデコードしようとしていますが、レスポンスを解析できないような問題が発生しています(json_decode
はNULL
を返します)。Google辞書APIのjson_decode
JSON応答の例はhere(「oracle」という語を検索しています)です。
JSON APIでは、コールバック関数を提出する必要があるため、処理が不要なため、実際には短いもの(a
)を選択しました。
<?php
$query = 'oracle';
$file = file_get_contents('http://www.google.com/dictionary/json?callback=a&q='.$query.'&sl=en&tl=en&restrict=pr,de&client=te');
var_dump($file);
$json = json_decode($file);
var_dump($json);
?>