What does `app.use(bodyParser.json())` do?

后端 未结 3 708
渐次进展
渐次进展 2020-12-22 20:21

For:

bodyParser.urlencoded({extended: ...})

my research shows me that if extended: true, then you can parse nested objects, or

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-22 20:47

    Okay, contrary to what I previously thought, further research shows that extended: true and app.use(bodyParser.json()) can be used together. So it is not only extended: false that uses it. The statement app.use(bodyParser.json()) is to be used independently, whether you set extended as true or false.

    • app.use(bodyParser.json()) basically tells the system that you want json to be used.

    • bodyParser.urlencoded({extended: ...}) basically tells the system whether you want to use a simple algorithm for shallow parsing (i.e. false) or complex algorithm for deep parsing that can deal with nested objects (i.e. true).

    Have a look at the docs (i.e. https://expressjs.com/en/guide/migrating-4.html) for the example.

提交回复
热议问题