javascript - 如何在 Javascript 中使用变量创建 JSON?
问题描述
我有返回 json 格式数组的代码,但我希望它位于“数据”下:所以现在,它显示为:
"["newDate": 'test'": 'test',"attendees": 'test,"name": 'Foo']"
我如何得到它: "{ data: ["newDate": 'test'": 'test',"attendees": 'test,"name": 'Foo'] }"
let countries = [];
for (x in newObj) {
countries.push({
"newDate": newObj[x][0],
"count": getDates()[x].length,
"attendees": getDates()[x],
"name": x
})
}
return JSON.stringify(countries);
解决方案
JSON.stringify({data:countries});
推荐阅读
- javascript - How to manage sessions in a small React WebApp?
- python - A python function that finds a number's largest divisor excluding itself
- php - 为什么我的 form_validation 不起作用?错误:未正确填写字段表单
- java - Intellij 终端的行为不同于 Ubuntu 终端的 pulseaudio/pacmd/pactrl 命令
- reactjs - how can fix refresh problem in react router
- c# - How to remove issue link from issue links (Atlassian Jira) with Atlassian C# SDK
- gradle - gradle recipe/archetype/generators for multi-modules kotlin nodejs backend and reactjs frontend
- c - 有人可以告诉我为什么它打印 1 而不是 2?
- mysql - 具有引用多个表的外键
- python - 取消订阅的条纹不适用于 Django