423,850 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,850 IT Pros & Developers. It's quick & easy.

Parsing JSON with PHP

P: 7
Hi all,
I have a JSON generated from API, but when I try to save, it shows that txt file. https://eutils.ncbi.nlm.nih.gov/entr...ed-univ.edu.vn

I write a short code to get the abstract in this link.
Expand|Select|Wrap|Line Numbers
  1. $api_json_url2 = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id=3321921&tool=my_tool&email=nhbach@huemed-univ.edu.vn";                            
  2. $json2 = file_get_contents($api_json_url2);
  3. $data2 = json_decode($json2, TRUE);
  5. $abstract =     $data['medent']['abstract'];    
But the result is nothing appear.

Please help to get the "abstract" part.

Thank you very much
Mar 22 '18 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 5,182
if i see it right - the response you get from that request is no valid json, thus it cant simply be parsed that way. your best bet with that response and your requirement would be to match everything after the text abstract which is enclosed in double quotes. I would suggest to use regular expressions for that - but there are different ways to extract that part from plain text. Its much easier then trying to fix the weird structure to a valid JSON to parse it as that.
Apr 11 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.