我的 JSON 响应中似乎有多余的键。知道为什么吗?
以下是 JSON 响应的摘录:
{
"0": "1",
"id": "1",
"1": "XX University",
"name": "XX University",
"2": "http:\/\/ree.com\/images\/xxUniversity.png",
"backgroundImageUrl": "http:\/\/ree.com\/images\/XXUniversityLogo.png",
"3": "http:\/\/ree.com\/images\/xxUniversity.png",
"logoImageUrl": "http:\/\/ree.com\/images\/XXUniversityLogo.png"
},
这是我的PHP代码:
$query = "SELECT * from $entity"; //Bad security,for a different question
$results = mysqli_query($con,$query);
//Parse to JSON
$json=array();
while($row=mysqli_fetch_array($results)){
$json[]=$row;
}
//Close connection
mysqli_close($con);
//Encode and send response as JSON (using the entity type as a parameter)
//echo json_encode(array($entity => $json), JSON_FORCE_OBJECT);
echo json_encode(array ($entity =>$json));