menu

Questions & Answers

Trying to fetch Json data from URL but not being successful

URL: https://clinicaltrials.gov/api/query/full_studies?expr=heart+attack&fields=NCTId,BriefTitle,BriefSummary,CollaboratorName&fmt=json

Trying to get the NCTId, BriefTitle, BriefSummary and OverallStatus parameters to be displayed on a page. But I am having a hard time just getting the parameters.

I am new to JSON, so any help appreciated.

I tried this to see if the BriefTitle would display:

$url='https://clinicaltrials.gov/api/query/field_values?expr=heart+attack&field=BriefTitle&fmt=json'; 


$JSON = file_get_contents($url);
$response_json_data = new RecursiveIteratorIterator(
    new RecursiveArrayIterator(json_decode($JSON, TRUE)),
    RecursiveIteratorIterator::SELF_FIRST);

foreach ($response_json_data as $key => $val) {
    if(!is_array($val)) {
        if($key == "BriefTitle") {
            print "<br/>";
        }
    print $key."    : ".$val . "<br/>";
    }
}
Comments:
2023-01-23 23:01:06
If you seek relevant answers you should mention/tag what language you are using. My guess is PHP?
2023-01-23 23:01:06
Correct. I am using PHP
2023-01-23 23:01:06
So why using jquery tag ?
2023-01-23 23:01:06
Use <?php $url='https://clinicaltrials.gov/api/query/full_studies?expr‌​=heart+attack&fields‌​=NCTId,BriefTitle,Br‌​iefSummary,Collabora‌​torName&fmt=json'; $JSON = json_decode(file_get_contents($url), true); echo($JSON["FullStudiesResponse"]["FullStudies"][0]["Study"]‌​["ProtocolSection"][‌​"IdentificationModul‌​e"]["NCTId"]);
Answers(0) :