comment gérer la clé dynamique JSONComment analyser la vale clé dynamique en php
[
{
"batch_id": "132",
"benf_id": "ANP-JAI-1190",
"NA3": "",
"NA4": "",
"status": "Y",
"NA5": "",
"datapoint_id": "105",
"status_update_time": "28/8/2017 ",
"user_id": "santoshk",
"pop_id": "40",
"measuring": "1000ltr",
"weight": "100gm"
},
{
"batch_id": "133",
"benf_id": "ANP-JAI-1195",
"NA3": "",
"NA4": "",
"status": "Y",
"NA5": "",
"datapoint_id": "106",
"status_update_time": "28/8/2017 ",
"user_id": "santoshk",
"pop_id": "41",
"water": "1000ltr",
"medicine": "100gm"
}
]
// mon code php
public function benf_status_update($jdata)
{
$count=0;
$this->load->model('m_sf_user');
while($count < count($jdata))
{
$batch_id = $jdata[$count]->batch_id;
$benf_id = $jdata[$count]->benf_id;
$m3=$jdata[$count]->NA3;
$m4=$jdata[$count]->NA4;
$status = $jdata[$count]->status;
$m5=$jdata[$count]->NA5;
$m1=$jdata[$count]->0;
$m2=$jdata[$count]->0;
$datapoint_id = $jdata[$count]->datapoint_id;
$status_update_time = $jdata[$count]->status_update_time;
$user_id =$jdata[$count]->user_id;
$pop_id = $jdata[$count]->pop_id;
$benf_id = substr($benf_id,8,strlen($benf_id));
$qry = "UPDATE pop_b_m_points a JOIN m_pop_batch b ON
b.pop_id=".$pop_id."
and b.batch_id=".$batch_id."
and a.data_p_id=b.dpoint_id
and a.benf_id=".$benf_id."
and a.m_point_id=".$datapoint_id."
SET a.status='".$status."',
a.m1='".$m1."',
a.m2='".$m2."',
a.m3='".$m3."',
a.m4='".$m4."',
a.m5='".$m5."' ,
a.update_time= (SELECT (DATE_FORMAT(STR_TO_DATE('".$status_update_time."', '%d/%m/%Y'), '%Y%m%d')))";
$this->m_sf_user->jSONservices_u($qry);
$count++;
}
$x=array('json_status'=>"success");
echo json_encode($x);
}