嗨,我有名字Users
表有這些列解決這個問題:如何使用json_encode(從數據庫PHP數組)導致
UserId INT
DisplayName VARCHAR(50)
Username VARCHAR(50)
Password VARCHAR(50)
我從這個表中的記錄與mysqli的(mysqli_query
,mysqli_fetch_array
)像這樣的:
$users=array();
while($user=mysqli_fetch_array($result)
$users=array("User"=>$user);
echo json_encode(array("Users"=>$users));
和json_encode的結果是:
{"users":{
"user":{
"0":"1",
"UserId":"1",
"1":"name",
"DisplayName":"name",
"2":"usernameTest",
"Username":"usernameTest",
"3":"passwordTest",
"Password":"passwordTest"
}
}}
但必須是:
{"users":{
"user":{
"UserId":"1",
"DisplayName":"name",
"Username":"usernameTest",
"Password":"passwordTest"
}
}}