20210916 - JSON
2021-09-16 00:00:00

后端发送的response是把updatedNote这个object转成JSON string

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
app.put('/api/notes/:id', (request, response, next) => {
const body = request.body

const note = {
content: body.content,
important: body.important,
}

Note.findByIdAndUpdate(request.params.id, note, {new: true})
.then(updatedNote => {
**// console.log(typeof updatedNote) // object**
response.json(updatedNote)
})
.catch(error => next(error))
})

前端接收到的整个response和response.data的类型都是object。

Untitled

Untitled

然而json的类型是string,为什么传回前端变成object了?还是说中间有更复杂的操作?