我有个问题。我SELECT从我的数据库执行以获取用户数据。现在,除了查询之外,我还得到了一些变量$result。我希望将所有数据添加到我的 json 中。这是我当前的代码:
if($result->num_rows == 1)
{
$access_token = "myToken";
$expires_in = 3600;
while($row = $result->fetch_object())
{
$arrTotal[] = array($row);
}
$myObj->access_token = $access_token;
$myObj->expires_in = $expires_in;
$data = array();
$data['user'] = $arrTotal;
$data['token'] = $myObj;
echo json_encode($data);
}
此当前代码生成以下 json:
{
"user":[
[
{
"Id":"0",
"Username":"Vreesie",
"ProfilePicture":""
}
]
],
"token":{
"access_token":"myToken",
"expires_in":"3600"
}
}
但我希望它看起来像这样:
{
"user":[
[
{
"Id":"0",
"Username":"Vreesie",
"ProfilePicture":""
}
]
],
"token":[
[
{
"access_token":"myToken",
"expires_in":"3600"
}
]
]
}
我怎样才能做到这一点?
呼啦一阵风
桃花长相依