简体   繁体   中英

how to print specific content in json with php

I have a json print like this;

https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=26162616&retmode=json&tool=my_tool&email=my_email@example.com

When i want to get result->26162616->pubdate i am getting error or null.

my code :

$source = file_get_contents("https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=26162616&retmode=json&tool=my_tool&email=my_email@example.com");
$source = json_decode($source);

echo $source->result->26162616->pubdate;

i think reason is integer 26162616 value.

how can i fix this?

Turn JSON into an associative array (true in json_decode) and reference as follows:

$source = json_decode($source, true);

echo $source["result"]["26162616"]["pubdate"]; // 2015 Aug

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM