首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从JSON URL获取DOI值列表

从JSON URL获取DOI值列表
EN

Stack Overflow用户
提问于 2019-03-05 19:40:31
回答 1查看 115关注 0票数 0

我有一个来自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-resultsDOI值的列表

代码语言:javascript
复制
$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列表。

请帮我找出我的代码的错误。谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-05 19:47:15

正确的代码:

代码语言:javascript
复制
$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'];  
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55002010

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档