javascript - How to import external JSON and display in php - Stack Overflow

I have a WordPress site for people with Multiple Sclerosis and to assist them in finding current clinic

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
Add a ment  | 

1 Answer 1

Reset to default 2

You 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745291955a4620913.html

相关推荐

  • javascript - How to import external JSON and display in php - Stack Overflow

    I have a WordPress site for people with Multiple Sclerosis and to assist them in finding current clinic

    14小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信