我有点困惑,我如何创建这样的响应数据。创建数据json php
[
{
"profile": "Profile 1",
"kumpulan_spot": [
{
"urutan": "1",
"id": "0415AA9E2D",
"checkpoint": "3. OFFICE DEPAN LT. 2",
"lokasi": "WARU",
"waktu": "none",
"status": "none",
"kondisi": "none",
"foto": "none"
},
{
"urutan": "2",
"id": "0415AAA007",
"checkpoint": "4. OFFICE KRIAN LT.3 - R. MIS",
"lokasi": "KRIAN",
"waktu": "none",
"status": "none",
"kondisi": "none",
"foto": "none"
}
]
},
{
"profile": "Profile 2",
"kumpulan_spot": [
{
"urutan": "3",
"id": "0415AAA01B",
"checkpoint": "2. OFFICE DEPAN LT.1 - R. MARKETING",
"lokasi": "KRIAN",
"waktu": "none",
"status": "none",
"kondisi": "none",
"foto": "none"
}
]
}
]
但到目前为止,我一直在努力
$myparams['nik'] = $_POST['nik'];
$procedure_params = array(
array(&$myparams['nik'] , SQLSRV_PARAM_IN)
);
$sql = "EXEC SP_GETJADWAL @nik=?";
$stmt = sqlsrv_prepare($conn, $sql,$procedure_params);
if(!$stmt) {
die(print_r(sqlsrv_errors(), true));
}
$return_hasil=[];
$myArray = [];
if(sqlsrv_execute($stmt)){
do {
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
$arrItem=[];
$detailItem=[];
// $i=0;
// while($i==0){
$arrItem["Profile"]="Profile ".$row['Profile'];
// $i=1;
// }
$detailCheckPoint=[];
$detailCheckPoint["urutan"]=$row['Urutan'];
$detailCheckPoint["id"]=$row['check_point_id'];
$detailCheckPoint["checkpoint"]=$row['check_point_name'];
$detailCheckPoint["lokasi"]=$row['check_point_loc'];
$detailCheckPoint["waktu"]="none";
$detailCheckPoint["status"]="none";
$detailCheckPoint["kondisi"]="none";
$detailCheckPoint["foto"]="none";
$detailItem[]=$detailCheckPoint;
$arrItem["ListCheckPoint"]=$detailItem;
$return_hasil[]=$arrItem;
}
} while (sqlsrv_next_result($stmt));
echo json_encode($return_hasil);
}else{
die(print_r(sqlsrv_errors(), true));
}
}else{
echo 'Connection Failure<br/>';
}
,并得到结果这样
[
{
"Profile": "Profile 1",
"ListCheckPoint": [
{
"urutan": "1",
"id": "0415AA9E2D",
"checkpoint": "3. OFFICE DEPAN LT. 2",
"lokasi": "WARU",
"waktu": "none",
"status": "none",
"kondisi": "none",
"foto": "none"
}
]
},
{
"Profile": "Profile 1",
"ListCheckPoint": [
{
"urutan": "2",
"id": "0415AAA007",
"checkpoint": "4. OFFICE KRIAN LT.3 - R. MIS",
"lokasi": "KRIAN",
"waktu": "none",
"status": "none",
"kondisi": "none",
"foto": "none"
}
]
},
{
"Profile": "Profile 1",
"ListCheckPoint": [
{
"urutan": "3",
"id": "0415AAA01B",
"checkpoint": "2. OFFICE DEPAN LT.1 - R. MARKETING",
"lokasi": "KRIAN",
"waktu": "none",
"status": "none",
"kondisi": "none",
"foto": "none"
}
]
}
]
创建数据JSON和点点即时通讯新困惑如何实现响应我想要
有什么问题?格式看起来正确。 –
你想在“kumpulan_spot”中插入多个数组。你决定在“kumpulan_spot”中放置元素的条件是什么? –
@TouheedKhan条件$ arrItem [“Profile”] =“Profile”。$ row ['Profile'];先生所以配置文件可以有很多kumpulan_spot –