无法定义JSON数组 [英] cannot define a JSON array

查看:68
本文介绍了无法定义JSON数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数据从JSON文件获取到有角度的应用程序中,问题是我将使用此文件作为本地数据库,并且它将包含多个数组,因此我必须命名该数组,但是当我尝试时将其定义为vs会指出错误.

I am trying to get data from a JSON file into an angular app, the thing is I will be using this file as a local database and it will contain more than one array so I have to name the array but when I try to define it the vs points it out as an error.

这是数组

var historybooks = [
{
    "name" : "book1",
    "id" : "his-1",
    "author" : "omar",
    "discription" : "lorem ipsum dolor ....",
    "image" : "./assets/books-images/book1.png"
}
]

vs错误预期的JSON对象,数组或文字."

vs error "Expected a JSON object, array or literal."

我也尝试用let代替var并得到相同的错误.

I also tried with let instead of var and get the same error.

推荐答案

您无法在JSON中声明变量.请删除声明.

You can't declare a variable inside a JSON.Remove the declaration.

如果要声明更多的数组,可以在同一文件中执行此操作:

If you want to declare more array's you can do this in the same file:

{
"array1":[{"key":"value","key":"value"}],
"array2":[{"key":"value","key":"value"}]
}

这篇关于无法定义JSON数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆