![](/img/trans.png)
[英]node.js, express, how to get data from body form-data in post request
[英]How to handle table JSON/form data from the body of the URL in node.JS and express
我有問題node.js快遞。 我的問題涉及 node.js 快遞的郵寄請求。 我想以 json 形式發布此數據的請求。 您可以在下面找到 node.js 快遞代碼和我想做的帖子。
node.js快遞編碼:
var express = require('express');
var app = express();
app.use(express.json()); // built-in middleware for express
app.post('/', function(request, response){
let myJson = request.body; // your JSON
let myValue = request.body.II.A; // a value from your JSON
response.send(myJson); // echo the result back
});
app.listen(3000);
======================
json 格式的帖子正文:
{
"I" : {
"Y" : "3",
"Z" : "2",
"T" : "1"
},
"II" : [
{
"A" : "4",
"B" : "5",
"C" : {"a": "4", "b" : "6"},
}
]
}
使用此代碼從帖子 API 獲取身體數據。
var express = require('express');
var bodyParser = require("body-parser");
var app = express();
app.use(express.json()); // built-in middleware for express
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/', function(request, response){
let myJson = request.body; // your JSON
let myValue = request.body.II.A; // a value from your JSON
response.send(myJson); // echo the result back
});
app.listen(3000);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.