Postman PUT JSON 返回 Null [英] Postman PUT JSON Returns Null

查看:36
本文介绍了Postman PUT JSON 返回 Null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个数组,我试图使用 PUT 来更改 statuses 的值.我正在使用 Postman(一个 REST 客户端——http://www.getpostman.com/).当我切换到 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 -- http://www.getpostman.com/). 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆