我有这个数组,我试图使用 PUT 来更改 statuses 的值.我正在使用 Postman(一个 REST 客户端——www.getpostman/).当我切换到 x-www-form-urlencoded 选项卡并将 statuses 的值放入 hello 时,它会相应地更新.结果如下.
[{__v: 0_id: "XYXYXYXYXYXYXYXYXYXYXYXY"标语:示例标语"title: "示例标题"状态:[你好"]}]但是当它变得比数组中的字符串更复杂时,我将选项卡更改为 raw 并尝试通过键入 {"statuses":[{"userId": true}]}.
做GET请求时,结果如下.
[{__v: 0_id: "XYXYXYXYXYXYXYXYXYXYXYXY"标语:示例标语"title: "示例标题"状态:空}]为什么我的 JSON PUT 请求返回 null?我怎样才能改变它?
解决方案我们需要查看您的 Node.js 代码才能最好地回答您,但我的猜测是(我想您正在使用 body-parser) 您需要将 extended 选项设置为 true 以便它能够解析更复杂的主体.
那就是:
app.use(bodyParser.urlencoded({extended: true}));I have this array that I am trying to use PUT to change the value of statuses. I am using Postman (A REST client -- www.getpostman/). When I change over to the x-www-form-urlencoded tab and put the value of statuses to hello it updates accordingly. Below would be the result.
[ { __v: 0 _id: "XYXYXYXYXYXYXYXYXYXYXYXY" tagline: "Example tagline" title: "Example title" statuses: ["hello"] } ]But when it gets more complex than a string in the array, I change the tab over to raw and try and do a JSON PUT request there by typing {"statuses":[{"userId": true}]}.
When doing a GET request, the following is the result.
[ { __v: 0 _id: "XYXYXYXYXYXYXYXYXYXYXYXY" tagline: "Example tagline" title: "Example title" statuses:null } ]How come my JSON PUT request returns null? How can I change that?
解决方案We need to see your Node.js code to best answer you, but my guess is (I suppose you're using body-parser) you need to set the extended option to true so that it's able to parse more complex bodies.
So that would be :
app.use(bodyParser.urlencoded({ extended: true}));
更多推荐
Postman PUT JSON 返回 Null
发布评论