[英]Json Arrays, json objects and json strings
hello i have the following php script to fetch data from mysql database but i have a problem passing the json response 您好,我有以下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);
and it produces the result 并产生结果
[{"first_name":"John","last_name":"Doe"}]
[{"first_name":"Doe","last_name":"John"}]
i would like it to produce 我想要生产
{
"users": [
{
"first_name": "John",
"last_name": "Doe"
},
{
"first_name": "Doe",
"last_name": "John"
}
]
}
I'm trying to get the json with retrofit using 我正在尝试使用翻新来获取json
@SerializedName("users")
I solved it simply by adding 我只需添加即可解决
echo json_encode(array("users"=>$data));
I guess trial an error actually helps us beginners when those with the knowledge to help us and save us time would rather down vote our questions. 我认为尝试错误实际上可以帮助我们的初学者,而那些知道如何帮助我们并节省我们时间的人宁愿不赞成我们的问题。 Wonder what they gain.
想知道他们获得了什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.