我一直在尝试将复杂的 json 数据记录推送到 json 变量中。这是我尝试这样做的代码。
var marks=[];
var studentData="student1":[{
"term1":[
{"LifeSkills":[{"obtained":"17","grade":"A","gp":"5"}]},
{"Work":[{"obtained":"13","grade":"A","gp":"5"}]}
]
"term2":[
{"LifeSkills":[{"obtained":"17","grade":"A","gp":"5"}]},
{"Work":[{"obtained":"13","grade":"A","gp":"5"}]}
]
}];
marks.push(studentData);
但它不会将任何内容推送到 json 数组。任何人都可以帮我摆脱这个问题。
最佳答案
DEMO 在这里我更正了你的 json 并检查了演示
var studentData={
"student1": [
{
"term1": [
{
"LifeSkills": [
{
"obtained": "17",
"grade": "A",
"gp": "5"
}
]
},
{
"Work": [
{
"obtained": "13",
"grade": "A",
"gp": "5"
}
]
}
],
"term2": [
{
"LifeSkills": [
{
"obtained": "17",
"grade": "A",
"gp": "5"
}
]
},
{
"Work": [
{
"obtained": "13",
"grade": "A",
"gp": "5"
}
]
}
]
}
]
}
var marks=[];
marks.push(studentData);
console.log(marks);
成功插入标记数组
关于javascript - 使用javascript将复杂的json记录推送到json变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28208693/