Php 如何将json数据加载到表中?

Php 如何将json数据加载到表中?,php,arrays,json,curl,Php,Arrays,Json,Curl,我正在使用php curl从API获取数据。我得到一个json回复。我想在桌子里面回音。我的答复是: Array ( [code] => 202 [message] => Accepted [data] => Array ( [resultMap] => Array ( [D2721~H16] => Array ( [AppDay] => * [HosTown] => Colombo [SpecName] => Psychologist [HosN

我正在使用php curl从API获取数据。我得到一个json回复。我想在桌子里面回音。我的答复是:

Array ( [code] => 202 [message] => Accepted [data] => Array ( [resultMap] => Array ( [D2721~H16] => Array ( [AppDay] => * [HosTown] => Colombo [SpecName] => Psychologist [HosName] => Ninewells Care [SpecializationId] => 36 [HosCode] => H16 [AppDate] => Any [DocName] => MS RANSIRINI DE SILVA [DoctorNo] => D2721 ) [D1656~H61] => Array ( [AppDay] => * [HosTown] => Pannipitiya [SpecName] => Psychologist [HosName] => Pannipitiya Nursing Home [SpecializationId] => 36 [HosCode] => H61 [AppDate] => Any [DocName] => MS ACHINI RANASINGHE [DoctorNo] => D1656 ) [D0465~H07] => Array ( [AppDay] => * [HosTown] => Colombo [SpecName] => Psychologist [HosName] => Lanka Hospitals [SpecializationId] => 36 [HosCode] => H07 [AppDate] => Any [DocName] => DR(MS) SHANEZ FERNANDO [DoctorNo] => D0465 ) [D1958~H44] => Array ( [AppDay] => * [HosTown] => Wattala [SpecName] => Psychologist [HosName] => Hemas 


curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($rawPOSTdata));

// Make the REST call, returning the result
$response = curl_exec($curl);
if (!$response)
    {
    die("Connection Failure.\n");
    }
// Convert the result from JSON format to a PHP array

$result = json_decode($response,true);
print_r($result);

curl_close($curl);
if ( isset($result->error) )
    {
    die($result->error_message."\n");
    } 
 }

我的第一个猜测是使用foreach语句遍历数组:

if(is_array($result) && !empty($result)) {    // check if we have some lines
    echo '<table>';

    foreach($result as $elem) {    // iterate through all the elements
        echo '<tr>';
        foreach($elem as $tdValue) {    // output all field values (if you want to output all of course)
            echo '<td>' . $tdValue . '</td>';
        }
        echo '</tr>';
    }

    echo '</table>';
}
if(is_array($result)&&&!empty($result)){//检查我们是否有一些行
回声';
foreach($result as$elem){//遍历所有元素
回声';
foreach($elem as$tdValue){//输出所有字段值(当然,如果您想输出所有字段值)
回显“.$tdValue.”;
}
回声';
}
回声';
}