我想将此 json 输出更改为以下样式,有什么想法吗?
我的代码:
$queryFunctions = $db->getChatRoomData($userID , $userName, $userMessage, $roomID);
$rows['roomInfo'] = array();
while ($result = mysql_fetch_array($queryFunctions, MYSQL_ASSOC))
{
$row['uid'] = $result['uid'];
$row['name'] = $result['userName'];
$row['message'] = $result['messageText'];
array_push($rows, $row);
}
echo json_encode($rows);
电流输出:
{"roomInfo":[],"0":{"uid":"50","name":"ali","message":"arz adab !"},"1":{"uid":"50","name":"ali","message":"arz adab !"},...}
期望的输出:
{"roomInfo" : [{"uid":"50","name":"ali","message":"arz adab !"},{"uid":"50","name":"ali","message":"arz adab !"},...}
提前致谢