【发布时间】:2017-08-23 10:54:31
【问题描述】:
这里我有一个 JSON 响应,在该响应中,我得到了诸如 companyId 和 DivisionName 等值...,现在我想找到 companyId 一个意味着我想找到公司名称是什么,所以写了一个函数并且我得到了公司名称,我的问题是这个名称我无法附加相同的对象
protected function getStates(){
// Cross validation if the request method is GET else it will return "Not Acceptable" status
if($this->get_request_method() != "GET"){
$response_array['status']='fail';
$response_array['message']='GET method only accept';
$response_array['data']='';
$this->response($this->json($response_array), 405);
}else{
$info_array = array(
"fields"=>"stateId,stateName,companyId",
"where"=>"stateStaus !='Inactive'"
);
$state_data = $this->GetRecords("state",$info_array);
if(count($state_data)>0) {
$companyId = $state_data['companyId'];
$check_info = array(
'fields'=>'companyName',
'where'=>'companyId = "'.$companyId.'" '
);
$companyName = $this->GetNameById('company',$check_info);
//$state_data['companyName'] = $companyName; //Company Name display
$response_array['status']='success';
$response_array['message']='Total '.count($state_data).' record(s) found.';
$response_array['total_record']= count($state_data);
$response_array['data']=$state_data;
$this->response($this->json($response_array), 200);
} else {
$response_array['status']='fail';
$response_array['message']='Record not found.';
$response_array['data']='';
$this->response($this->json($response_array), 506);
}
}
}
$this->response($this->json($response_array), 200); (我得到回应)
{
"status": "success",
"message": "Total 3 record(s) found.",
"total_record": 3,
"data": [
{
"stateId": "3",
"stateName": "Odisha",
"companyId": "1"
},
{
"stateId": "2",
"stateName": "Tamil Nadu",
"companyId": "1"
},
{
"stateId": "1",
"stateName": "Karnadaka",
"companyId": "1"
}
]
}
为了找到 companyName,我写了一个函数 $companyName = $this->GetNameById('company',$check_info); 在这里我得到了公司名称(Cibla)。
我的预期结果
{
"status": "success",
"message": "Total 3 record(s) found.",
"total_record": 3,
"data": [
{
"stateId": "3",
"stateName": "Odisha",
"companyId": "1",
"companyName" : "Cibla"
},
{
"stateId": "2",
"stateName": "Tamil Nadu",
"companyId": "1",
"companyName" : "Cibla"
},
{
"stateId": "1",
"stateName": "Karnadaka",
"companyId": "1",
"companyName" : "Cibla"
}
]
}
【问题讨论】:
-
请保留使用块引用格式 (
>) 进行报价。不要用它来“突出显示”部分。您根本不需要格式化;这应该以纯文本形式设置。