簡體   English   中英

如何使用PHP從JSON獲取值

[英]How to get the value from json with PHP

我怎樣才能得到源,標題,ISSN,作者,...從JSON文件: 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數據庫生成)的解決方案嗎?

謝謝。

您沒有使用$data變量,該變量存儲了已解碼的數據

您將JSON解碼為$data作為數組

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

-更新-

要獲取$authors名稱,authtype,...,請使用foreach循環:

foreach($authors as $author){
    $name = $author['name'];
    $authtype = $author['authtype'];
    $clusterid = $author['clusterid'];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM