admin管理员组文章数量:1418608
I have a WordPress site for people with Multiple Sclerosis and to assist them in finding current clinical trials that are recruiting participants I have an external JSON file of search results I want to display on my site.
Here is a sample output from the JSON:
{"intervention_browse":{"mesh_term":["Copolymer 1"]},"id_info":{"nct_id":"NCT00004814"},"sponsors":{"collaborator":[{"agency":"University of Maryland","agency_class":"Other"}],"lead_sponsor":{"agency":"National Center for Research Resources (NCRR)","agency_class":"NIH"}},"overall_status":"Completed","condition_browse":{"mesh_term":["Multiple Sclerosis","Sclerosis","Multiple Sclerosis, Relapsing-Remitting"]}}
What would be the best way to do this? An example using cURL or JSON_decode would be nice. (I only know enough to get myself into trouble, so assume I'm in kindergarten please. :) )
Since it's going into a WordPress site, should I use PHP or javascript or a bination of both for displaying it?
Once I get the information to display on my site I have no problem styling it with css. Getting it on the page is my main issue.
I have installed a plugin that allows me to add php directly into any page or post using shortcodes, but what code to put there is what's holding me up.
Here is the JSON file:.json?query=cond:%22Multiple+Sclerosis%2C+Relapsing-Remitting%22&fields=id_info.nct_id,condition_browse,sponsors,intervention_browse,overall_status&limit=1000
I have a WordPress site for people with Multiple Sclerosis and to assist them in finding current clinical trials that are recruiting participants I have an external JSON file of search results I want to display on my site.
Here is a sample output from the JSON:
{"intervention_browse":{"mesh_term":["Copolymer 1"]},"id_info":{"nct_id":"NCT00004814"},"sponsors":{"collaborator":[{"agency":"University of Maryland","agency_class":"Other"}],"lead_sponsor":{"agency":"National Center for Research Resources (NCRR)","agency_class":"NIH"}},"overall_status":"Completed","condition_browse":{"mesh_term":["Multiple Sclerosis","Sclerosis","Multiple Sclerosis, Relapsing-Remitting"]}}
What would be the best way to do this? An example using cURL or JSON_decode would be nice. (I only know enough to get myself into trouble, so assume I'm in kindergarten please. :) )
Since it's going into a WordPress site, should I use PHP or javascript or a bination of both for displaying it?
Once I get the information to display on my site I have no problem styling it with css. Getting it on the page is my main issue.
I have installed a plugin that allows me to add php directly into any page or post using shortcodes, but what code to put there is what's holding me up.
Here is the JSON file:http://api.lillycoi./v1/trials/search.json?query=cond:%22Multiple+Sclerosis%2C+Relapsing-Remitting%22&fields=id_info.nct_id,condition_browse,sponsors,intervention_browse,overall_status&limit=1000
Share Improve this question edited Sep 18, 2013 at 20:24 Diodeus - James MacFarlane 114k33 gold badges163 silver badges180 bronze badges asked Sep 18, 2013 at 20:23 Jeri BurtchellJeri Burtchell 211 gold badge1 silver badge2 bronze badges 5- Does php/manual/en/function.json-decode.php not help? Please include the attempted code in your question. – Amal Commented Sep 18, 2013 at 20:28
- I don't understand how to decode JSON and implement it, so I have no failed code to show you, rather I'm asking for basic help to get it working. – Jeri Burtchell Commented Sep 18, 2013 at 20:31
- In that case, start by reading the PHP manual. Check the link I gave above. Also, the search feature on StackOverflow is awesome. Here's one post to get you started: stackoverflow./questions/6571090/ – Amal Commented Sep 18, 2013 at 20:34
- i would use a client-side template that can consume json. angular works, but that's probably overkill. the datatables jQuery plugin can consume JSON if you want to offer a datagrid. – dandavis Commented Sep 18, 2013 at 20:35
- Thanks to you both and I apologize for asking something that has been answered before. Although I have been searching Stackoverflow and elsewhere for hours, I didn't understand the answers enough to take what I found and customize it for my own use. – Jeri Burtchell Commented Sep 18, 2013 at 20:43
1 Answer
Reset to default 2You can follow it:
<?php
$url = "http://api.lillycoi./v1/trials/search.json?query=cond:%22Multiple+Sclerosis%2C+Relapsing-Remitting%22&fields=id_info.nct_id,condition_browse,sponsors,intervention_browse,overall_status&limit=1000";
$json = file_get_contents($url);
$data = json_decode($json, TRUE);
?>
You can use var_dump or print_r to know what's in your data :
<?php var_dump($data); ?>
or
<?php print_r($data); ?>
The TRUE returns an array instead of an object.
本文标签: javascriptHow to import external JSON and display in phpStack Overflow
版权声明:本文标题:javascript - How to import external JSON and display in php - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745291954a2651849.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论