このようにコントローラーJSON
でMySQLデータベースからフォーマットでデータを出力していますが、
function byId(){
$this -> load -> model('usermodel');
$data['user'] = $this -> usermodel -> getById($this->uri->slash_segment(3));
$this -> output -> set_content_type('application/json');
$this -> output -> set_output(json_encode($data));
}
モデル:
function getById($id){
$this->db->select('*');
$this->db->from('members');
$this->db->where('id', $id);
$q = $this -> db -> get();
if ($q -> num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
このようなデータを出力します。
{"user":[{"id":"3","firstname":"Frances","lastname":"Johnson","address":"489 Summit Lane","state":"Minnesota","country":"US","email":"fjohnson@teklist.net","phone":null,"experience":"2","designation":"Script"}]}
しかし、私はこのようにそれを必要とします、
{user : {....} }
基本的に、角かっこを取り除きたいです。
意図した出力を得るために、コードで何を変更できますか?