0
我正在使用phil sturgeon的codeigniter休息。如何在json codeigniter rest服務器中返回json對象的編碼json
我想返回一個JSON對象,其中包含另一個JSON對象。
我的代碼看起來像這樣
function volunteer_get()
{
if(!$this->get('id'))
{
$this->response(NULL, 400);
}
$this->load->model('user/users_model');
$user = $this->users_model->get($this->get('id'));
$address = $this->address_model->getAddress($this->get('id'));
$user->address = $address;
$userJson = json_encode($user);
var_dump($userJson);
/*if($user && $user->auth_level == 1)
{
$this->response($userJson, 200); // 200 being the HTTP response code
}
else
{
$this->response(NULL, 404);
}*/
}
它沒有顯示任何結果......如果我這樣做,而不在其他PHP對象加入PHP對象,它讓我看到JSON!
D:\wamp\www\codeigniter\application\controllers\api\Users.php:37:string '{"user_id":"1","username":"abc","email":"abc","auth_level":"1","banned":null,"passwd":"abcdefg","passwd_recovery_code":"abcdefg","passwd_recovery_date":"2017-06-12 18:50:31","passwd_modified_at":"2016-11-18 21:20:30","last_login":"2017-08-30 15:10:36","created_at":"2016-09-02 12:01:46","modified_at":"2017-08-30 15:22:45","first_name":"aze","family_name":"'... (length=1354)
是'$ user'數組或對象?試試'echo gettype($ user);'讓我知道它顯示了什麼。 – MonkeyZeus