本文共 693 字,大约阅读时间需要 2 分钟。
express json
When you listen for connections on a route in Express, the callback function will be invoked on every network call with a Request object instance and a Response object instance.
当您在Express中侦听路由上的连接时,将在每个带有请求对象实例和响应对象实例的网络调用中调用回调函数。
Example:
例:
app.get('/', (req, res) => res.send('Hello World!'))
Here we used the Response.send()
method, which accepts any string.
在这里,我们使用了Response.send()
方法,该方法可以接受任何字符串。
You can send to the client by using Response.json()
, a useful method.
您可以使用Response.json()
(一种有用的方法Response.json()
将发送到客户端。
It accepts an object or array, and converts it to JSON before sending it:
它接受一个对象或数组,并在发送之前将其转换为JSON:
res.json({ username: 'Flavio' })
翻译自:
express json
转载地址:http://koqgb.baihongyu.com/