Postman PUT JSON 返回 Null

编程入门 行业动态 更新时间:2024-10-25 18:31:37
本文介绍了Postman PUT JSON 返回 Null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这个数组,我试图使用 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

本文发布于:2023-10-29 10:28:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539449.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PUT   Postman   Null   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!