php ci json,如何在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)

2017-10-05

Dennis

+0

是'$ user'数组或对象?试试'echo gettype($ user);'让我知道它显示了什么。 –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值