【发布时间】:2019-02-07 09:55:54
【问题描述】:
我目前以这种格式返回 JSON 到 ajax 调用:
[
{"username":"test3","points":62,"sportName":"Basketball"},
{"username":"test2","points":55,"sportName":"Football"}
]
但我想要这样:
{
“数据”:
[
{“用户名”:“test3”,“积分”:“62”,“运动名”:“篮球”},
{“用户名”:” test2", "points":"55", "sportName":"Football" }
]
}
返回它的函数(Laravel):
$scores=DB::select("SELECT user.username, points
FROM scores
JOIN users AS user ON user.id = scores.user_id
ORDER BY points DESC");
return json_encode($scores);
【问题讨论】:
-
请使用 Snippet
[<>]按钮及其Tidy选项来格式化您的代码。 -
你需要字符串
points吗?