Difference between res.send and res.json in Express.js Moving an answer on stackoverflow
The following is the translated answer with high votes:
When passing objects or arrays, these two methods are the same, but res.json() will also convert non-objects, such as null and undefined, these are invalid JSON. res.json()也会转换非对象,如null和undefined,这些无效的JSON。
🎜 Passed to JSON.stringify() is similar to: 🎜
rrreee
🎜 Code that is not included in the res.send part of the res.json method: 🎜
rrreee
🎜Finally it uses res.send to send the request🎜
rrreee
Difference between res.send and res.json in Express.js Moving an answer on stackoverflow
The following is the translated answer with high votes:
When passing objects or arrays, these two methods are the same, but
res.json()
will also convert non-objects, such asnull
andundefined, these are invalid JSON.
res.json()
也会转换非对象,如null
和undefined
,这些无效的JSON。该方法还使用
json replaceacer
和json spaces
的设置,因此您可以使用更多选项格式化JSON。 例如:传递给
JSON.stringify()
类似:res.json
方法的中res.send
部分没有的代码:最终它使用
This method also uses the settings ofres.send
json replaceacer
andjson spaces
so you can format JSON with more options. For example: 🎜 🎜 Passed toJSON.stringify()
is similar to: 🎜 rrreee 🎜 Code that is not included in theres.send
part of theres.json
method: 🎜 rrreee 🎜Finally it usesres.send
to send the request🎜 rrreee