json返信に変数を割り当てたいと思います。これは私のコードであるjson返信に変数を割り当てる方法
{"code":"202","message":"Accepted","data":{"resultMap":{"D1509~H24":{"AppDay":"*","HosTown":"Colombo","SpecName":"Physiotherapist","HosName":"Western Infirmary Hospital (Pvt) Ltd","SpecializationId":"34","HosCode":"H24","AppDate":"Any","DocName":"MR M. HAJITH","DoctorNo":"D1509"},"D0625~H08":{"AppDay":"*","HosTown":"Colombo","SpecName":"Physiotherapist","HosName":"Park Hospital (Pvt) Ltd ","SpecializationId":"34","HosCode":"H08","AppDate":"Any","DocName":"MR JALIYA UDUWELLA","DoctorNo":"D0625"},"D1762~H16":
が、私は、エラーメッセージ取得しています:
未定義のインデックスを、私はこれが私の返事で選択されたデータのみ
をエコーするために、その変数を使用したいです:このresultMapはC:\ WAMP \ WWW \ echanalling \
上
test.phpを
if (isset($_POST['submit']))
{
require 'gettoken1.php';
{
$baseurl = 'http://202.124.173.189/api/v1/doctorAvailability';
$curl = curl_init($baseurl);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json',"Authorization: Bearer $atoken"));
// Set the POST arguments to pass to the Sugar server
$rawPOSTdata = array(
"type" => "private",
"hosID" => $_POST['hosMaptxt'],
"specID" => $_POST['specialityMaptxt'],
"date" => $_POST['date'],
"name" => '%'.$_POST['docname'].'%'
);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($rawPOSTdata));
$response = curl_exec($curl);
curl_close($curl);
if (!$response)
{
die("Connection Failure.\n");
$result = json_decode($response,true);
$json=$result['data']['resultMap'];
$html=array();
$output[]="<table><tr> ";
foreach($result['resultMap']as $data)
{
$output.="<td>".$data['SpecName']."</td>";
$output.="<td>".$data['HosName']."</td>";
$output.="<td>".$data['DocName']."</td>";
$output.="<td>".$data['DoctorNo']."</td>";
$output.="<td>".$data['AppDay']."</td>";
$output.="<td>".$data['HosTown']."</td>";
}
$output .="</tr></table>";
echo $output;
}
curl_close($curl);
if (isset($result->error))
{
die($result->error_message."\n");
}
}
?>
'$ result'を受け取る方法を表示する – Justinas