我正在开发一个 Angular 4 应用程序。我正在尝试从 JSON 文件中获取数据以构建用户仪表板。
我创建了一个 json 文件并尝试使用 JSON 服务器加载它:$ json-server --watch user.json
我收到以下错误:
不支持 user.json 中的“id”(数字)类型。使用对象或对象数组。.
当我删除文件中的“id”字段时,我得到与“name”相同的错误。
我觉得我创建 json 文件的方式有问题。我是 Web 开发的新手,所以不要介意这是一个非常根本的错误。
这是我的 json 文件:
{
"id": 1,
"name":"Kajal Agarwal",
"department":"Information Technology",
"college":"Indian Institute of Engineering Science and Technology, Shibpur",
"subjects":[
{
"title":"Data Structures",
"active":true,
"faculty":"Prasun Ghosal",
"notifications":4,
"color":"#9c27b0"
},
{
"title":"Operating System",
"active":true,
"faculty":"Niharika Singh",
"notifications":0,
"color":"#ffc107"
},
{
"title":"Algorithms",
"active":true,
"faculty":"Debojit Mondal",
"notifications":1,
"color":"#009688"
},
{
"title":"Web Technologies",
"active":true,
"faculty":"Shantanu Saurabh",
"notifications":2,
"color":"#ff5722"
},
{
"title":"Formal Language and Automata Theory",
"active":true,
"faculty":"Sudhanshu Sekhar",
"notifications":3,
"color":"#03a9f4"
},
{
"title":"Digital Logic and Circuit Design",
"active":false,
"faculty":"",
"notifications":0,
"color":"#9e9e9e"
}
]
}