【发布时间】:2016-09-19 03:21:14
【问题描述】:
我在从以下代码获取 JSON 对象数组时遇到问题。
public function staffStatusFromSameDept($deptID)
{
$sameDeptEmployee=StaffsModel::where("DepartmentID","=",$deptID)->get();
$count=$sameDeptEmployee->count();
if ($count>0)
{
foreach ($sameDeptEmployee as $value)
{
$data=DB::table('status')
->join('staffs','status.StaffPin', '=', 'staffs.StaffPin')
->select('staffs.StaffName','staffs.DesignationName',
'status.staffStatus', 'status.currentLocation',
'staffs.EmailID','staffs.MobileNO','status.returnTime','staffs.Photo' )
->where('staffs.StaffPin','=',$value->StaffPin)
->get();
$response[]=$data;
}
}
else{
$response=["error" => "Invalid Department ID"];
}
header('Content-type: application/json');
echo json_encode($response);
}
实际输出:
[[{"StaffName":"Mamun hoten","DesignationName":"PO(MF)","staffStatus":"working","currentLocation":"rangpur","EmailID":"mamun@brac .net","MobileNO":"01716340278","returnTime":"04:30","Photo":"helal.jpg"}],[{"StaffName":"nahid hasan","DesignationName":"PO(MF)","staffStatus":"working","currentLocation":"rangpur","EmailID":"nahid@brac.net","MobileNO":"01716340278", "returnTime":"04:30","照片":"helal.jpg"}]]
预期输出:
[{"StaffName":"Mamun hooken","DesignationName":"PO(MF)","staffStatus":"working","currentLocation":"rangpur","EmailID":"mamun@brac. net","MobileNO":"01716340278","returnTime":"04:30","Photo":"helal.jpg"},{"StaffName":"nahid hasan","DesignationName":"PO(MF)","staffStatus":"working","currentLocation":"rangpur","EmailID":"nahid@brac.net","MobileNO":"01716340278", "returnTime":"04:30","照片":"helal.jpg"}]
我的代码中的问题是每个人都详细介绍了 JSON 对象数组。但是我想要一个 JSON 对象数组以及我将从这个 JSON 对象数组中获得的每个人的详细信息。
【问题讨论】: