我有一个JSON文件,用于存储正在构建的Quote Generator的报价。
最近,我在终端中收到此错误(请参见下面的屏幕截图)。Expected a JSON object, array or literal.json
这就是我的JSON的样子
data = [
{
"number": "1",
"author": "Von R. Glitschka",
"quote": "The client may be king, but he's not the art director."
},
{
"number": "2",
"author": "Frank Capra",
"quote": "A hunch is creativity trying to tell you something."
},
{
"number": "3",
"author": "Steven Heller",
"quote": "As a profession, graphic designers have been shamefully remiss or ineffective about plying their craft for social or political betterment."
}]
我已经尽力了。但是错误不断出现,这可能是什么问题?
最佳答案
您只需要对文件进行格式化,如下所示:
{
"data" : [
{
"number": "1",
"author": "Von R. Glitschka",
"quote": "The client may be king, but he's not the art director."
},
{
"number": "2",
"author": "Frank Capra",
"quote": "A hunch is creativity trying to tell you something."
},
{
"number": "3",
"author": "Steven Heller",
"quote": "As a profession, graphic designers have been shamefully remiss or ineffective about plying their craft for social or political betterment."
}]
}
并使用
.json
扩展名保存。
关于javascript - 需要一个JSON对象,数组或literal.json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53823706/