0

如何从 json 文件中获取来源、标题、issn、作者……:JSON 文件

我们尝试过:

$new_pmid = $_POST['new_pmid'];
$api_json_url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=".$new_pmid."&retmode=json";                          
$json = file_get_contents($api_json_url);
$data = json_decode($json, TRUE);

echo $header[0]->result->$new_pmid->title;  
....

但是什么都没有发生...

你能给我 json 文件的解决方案(从 pubmed 数据库生成)。

谢谢你。

4

2 回答 2

0

您将 JSON 解码$data为数组

$title = $data['result'][$new_pmid]['title'];
$issn = $data['result'][$new_pmid]['issn'];
$authors = $data['result'][$new_pmid]['authors'];

- 更新 -

要获取$authorsname ,authtype ,... 使用 foreach 循环:

foreach($authors as $author){
    $name = $author['name'];
    $authtype = $author['authtype'];
    $clusterid = $author['clusterid'];
}
于 2018-03-18T06:38:52.620 回答
0

您没有使用$data存储解码数据的变量

于 2018-03-18T06:32:23.717 回答