我从Web API中提取数据,返回类似这样的数据
[
{
"ID": 1,
"Name": "Puru Farms",
"Farm_Size": "24 acres",
"Town": "Dansoman",
"Farm_Owner_ID": 6,
"Route_ID": 1,
"Region_ID": 1,
"District_ID": 9
}
]
但我希望以这种格式返回数据
{"data":
[
{
"ID": 1,
"Name": "Puru Farms",
"Farm_Size": "24 acres",
"Town": "Dansoman",
"Farm_Owner_ID": 6,
"Route_ID": 1,
"Region_ID": 1,
"District_ID": 9
}
]}
从API返回包含此echo json_encode($data);
答案 0 :(得分:0)
试试这个
替换你的
json_encode($data)
与
$newdata["data"] = $data;
json_encode($newdata);
答案 1 :(得分:0)
返回你的json数据: -
json_encode(['data' => $data]);