3
我試圖用PHP解碼Google Dictionary API的JSON響應,但我遇到了一個問題,我似乎無法解析響應(json_decode
返回NULL
)。谷歌字典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);
?>