Php Json数组、Json对象和Json字符串

Php Json数组、Json对象和Json字符串,php,arrays,json,retrofit2,Php,Arrays,Json,Retrofit2,您好,我有下面的php脚本从mysql数据库获取数据,但是我在传递json响应时遇到了问题 $data=[]; while($row=mysqli_fetch_assoc($result)) { array_push($data,[ 'first_name' => $row['first_name'], 'last_name' => $row['last_name'],

您好,我有下面的php脚本从mysql数据库获取数据,但是我在传递json响应时遇到了问题

$data=[];

    while($row=mysqli_fetch_assoc($result))

    {
      array_push($data,[
                    'first_name' => $row['first_name'],
                    'last_name' => $row['last_name'],
                    ]);

    }

    echo json_encode($data);
它产生了结果

[{"first_name":"John","last_name":"Doe"}]
[{"first_name":"Doe","last_name":"John"}]
我想让它生产

{
"users": [
    {
        "first_name": "John",
        "last_name": "Doe"
    },
    {
       "first_name": "Doe",
        "last_name": "John"
    }
    ]
}
我试图通过使用

@SerializedName("users")

我简单地通过添加

echo json_encode(array("users"=>$data));
我想,当那个些有知识帮助我们并节省我们时间的人宁愿否决我们的问题时,试错实际上对我们初学者有帮助。想知道他们得到了什么