这太基本了,但我试图用谷歌搜索,但很难解释我需要搜索的关键字是什么。
这是我的Json
{
people: [
{
id: "1",
fname: "sadas",
lname: "asdad",
age: "12"
},
{
id: "2",
fname: "dfdfdf",
lname: "dfdfdf",
age: "334"
},
{
id: "3",
fname: "sdf",
lname: "sdf",
age: "343"
},
{
id: "4",
fname: "dsfsdf",
lname: "sdfsd",
age: "4"
}
],
success: 1
}
我需要在每个 json 对象都有类似标题的东西之前。像这样
{
people: [
person: {
id: "1",
fname: "sadas",
lname: "asdad",
age: "12"
},
person:{
id: "2",
fname: "dfdfdf",
lname: "dfdfdf",
age: "334"
},
person:{
id: "3",
fname: "sdf",
lname: "sdf",
age: "343"
},
person:{
id: "4",
fname: "dsfsdf",
lname: "sdfsd",
age: "4"
}
],
success: 1
}
这是我的php代码
while ($row = mysql_fetch_array($result)) {
$people= array();
$people["id"] = $row["id"];
$people["fname"] = $row["fname"];
$people["lname"] = $row["lname"];
$people["age"] = $row["age"];
array_push($response["people"] , $people);
}
$response["success"] = 1;
echo json_encode($response);
请帮助我任何帮助将不胜感激!