【发布时间】:2018-07-05 21:06:35
【问题描述】:
我已经设置了一个名为questions 的Array,我正在将一个API 的结果推送到Array,这没有问题。
如果我对数组进行硬编码,我会这样设置它。
var questions = [
{
"The Eiffel Tower is located where in Paris?": [
"Champ de Mars",
"Bois de Boulogne",
"Jardin des Plantes",
"Parc de Belleville"
]
}
]
但是当我使用questions.push 方法时,我会得到这样的结果:
var questions = [ '
{
"Which of the following was not one of 'The Magnificent Seven'?": [
"Clint Eastwood",
"Steve McQueen",
"Charles Bronson",
"Robert Vaughn"
]
}']
为什么会在我的结果中添加一个奇怪的'?
这是我将信息添加到数组中的方法:
var qdata = "{ \"" + question + "\":[ \"" + answer1 + "\", \"" + answer2 + "\", \"" + answer3 + "\", \"" + answer4 + "\"" + "]}";
questions.push(qdata);
我不明白为什么它将' 添加到我的数组中。
【问题讨论】:
-
奇怪的问题是由于奇怪的用法。你为什么要这样构造数组?为什么不是普通的旧
var arr = [] // etc code be here? -
如果你想要一个对象,你为什么要构建一个字符串?
-
以前从未使用过数组,这是一个新项目,并且知道我犯了一个错误,这就是我寻求帮助的原因
标签: javascript arrays json node.js arraylist