路径得不到
来源:8-4 使用 Postman 测试 API
All_Good
2019-09-18
老师,学生有两个问题:
{
"success":true,
"data":{
"allocations": [{
"id":1,
"campus": "St Lucia",
"building": "Advanced Engineer",
"category": "IT",
"level": "1",
"roomNumber": "12",
"seatNumber": "33",
"name": "sen",
"email": "652143408@qq.com",
"project": "website",
"supervisor": "Bruce",
"role": "Phd",
"ptorNot": "no",
"starDate": "11-1-2019",
"endDate": "12-1-2019"
},
{
"id":2,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "2",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":3,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "3",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":4,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "4",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":5,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "5",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":6,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "6",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":7,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "7",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":8,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "8",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":9,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "9",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":10,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "10",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":11,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "11",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":12,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "12",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":13,
"campus": "St Lucia",
"building": "Axon",
"category": "library",
"level": "13",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":14,
"campus": "St Lucia",
"building": "Sir Llew Edwards",
"category": "library",
"level": "14",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":15,
"campus": "St Lucia",
"building": "Banana",
"category": "IT",
"level": "1",
"roomNumber": "12",
"seatNumber": "33",
"name": "sen",
"email": "652143408@qq.com",
"project": "website",
"supervisor": "Bruce",
"role": "Phd",
"ptorNot": "no",
"starDate": "11-1-2019",
"endDate": "12-1-2019"
}
]
}
}
如果想要在返回的json中放置一个success去判断是否正确得到,但是json-server好像不允许?
{
"data":{
"allocations": [{
"id":1,
"campus": "St Lucia",
"building": "Advanced Engineer",
"category": "IT",
"level": "1",
"roomNumber": "12",
"seatNumber": "33",
"name": "sen",
"email": "652143408@qq.com",
"project": "website",
"supervisor": "Bruce",
"role": "Phd",
"ptorNot": "no",
"starDate": "11-1-2019",
"endDate": "12-1-2019"
},
{
"id":2,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "2",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":3,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "3",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":4,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "4",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":5,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "5",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":6,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "6",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":7,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "7",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":8,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "8",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":9,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "9",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":10,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "10",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":11,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "11",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":12,
"campus": "St Lucia",
"building": "Duhig North",
"category": "library",
"level": "12",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":13,
"campus": "St Lucia",
"building": "Axon",
"category": "library",
"level": "13",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":14,
"campus": "St Lucia",
"building": "Sir Llew Edwards",
"category": "library",
"level": "14",
"roomNumber": "888",
"seatNumber": "999",
"name": "Mike",
"email": "888888@qq.com",
"project": "App",
"supervisor": "MJ",
"role": "Singer",
"ptorNot": "no",
"starDate": "10-1-2019",
"endDate": "12-22-2019"
},
{
"id":15,
"campus": "St Lucia",
"building": "Banana",
"category": "IT",
"level": "1",
"roomNumber": "12",
"seatNumber": "33",
"name": "sen",
"email": "652143408@qq.com",
"project": "website",
"supervisor": "Bruce",
"role": "Phd",
"ptorNot": "no",
"starDate": "11-1-2019",
"endDate": "12-1-2019"
}
]
}
}
如果没有boolean,但是直接显示allocations里面的内容呢?
目前显示是这样的:
http://localhost:3000/data
但是,能不能直接显示下面这个图呢
写回答
1回答
-
张轩
2019-09-18
同学你好 json server 是为快速搭建一个可测试,支持 CRUD 的服务器所存在的。
第一个问题:它不支持自定义属性,比如你说的 success
第二个问题: 它是直接通过属性名称生成路由的,所以你可以直接把外层的 data 属性 删除,第一层就是 allocations,然后就可以通过 localhost:3000/allocations 访问数据了,更多的内容,可以多看看文档欧
https://github.com/typicode/json-server
012019-09-20
相似问题