Questions & Answers

Trying to fetch Json data from URL but not being successful


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:


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

foreach ($response_json_data as $key => $val) {
    if(!is_array($val)) {
        if($key == "BriefTitle") {
            print "<br/>";
    print $key."    : ".$val . "<br/>";
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='‌​=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) :