[英]Get the list of DOI value from JSON URL
我有一個來自URL的簡短JSON文件
https://api.crossref.org/works?query.title=Tuberculosis+drug&filter=type:journal-article,from-print-pub-date:2010,until-print-pub-date:2010&select=DOI&rows=3
我使用此代碼獲取total-results
和DOI
值列表
$crossref_api_url = 'https://api.crossref.org/works?query.title=Tuberculosis+drug&filter=type:journal-article,from-print-pub-date:2010,until-print-pub-date:2010&select=DOI&rows=2';
$JSON = file_get_contents($crossref_api_url);
$Array = json_decode($JSON, true);
$items_list = $message->items;
$totalItems = $message->total-results;
echo $totalItems;
for($i = 0; $i < count($items_list ); $i++) {
$doi = $items_list[$i]->items->DOI;
echo $doi;
}
結果顯示為0
。 沒有totalItems
值, DOI
列表。
請幫助我找到我的代碼錯誤。 謝謝
正確的代碼:
$crossref_api_url = 'https://api.crossref.org/works?query.title=Tuberculosis+drug&filter=type:journal-article,from-print-pub-date:2010,until-print-pub-date:2010&select=DOI&rows=2';
$JSON = file_get_contents($crossref_api_url);
$Array = json_decode($JSON, true); // with `true` you decode to ARRAY
$items_list = $Array['message']['items'];
$totalItems = $Array['message']['total-results'];
echo $totalItems;
foreach ($items_list as $item) {
echo $item['DOI'];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.