我是 API 的新手,我使用 Codeigniter 从 MySql 数据库产品创建一个 API,该产品具有以下字段:Amount、quantity、customerName、CustomerPhone、CustomerAddress 结果看起来:
```[
{
"Id": "1",
"Amount": "21542",
"quantity": "52",
"customerName": "John",
"CustomerPhone": "254215",
"CustomerAddress": "road tvz120",
},```
但我希望它看起来像这样:
```[
{
"Id": "1",
"Amount": "21542",
"quantity": "52",
"customerInfo":{
"customerName": "John",
"CustomerPhone": "254215",
"CustomerAddress": "rue tvz120"},
},```
我的意思是用名称 customer info 将 3 个字段 concernign customers 分组
我的PHP代码是
```public function index_get($id = 0)
{
if(!empty($id)){
$data = $this->db->get_where("Products", ['Id' => $id])->row_array();
}else{
$data = $this->db->get("Products")->result();
}
$this->response($data, REST_Controller::HTTP_OK);
}```
慕无忌1623718
GCT1015