如何在Node.js Express服务中的查询参数中发送整数 [英] How to send integers in query parameters in nodejs Express service

查看:97
本文介绍了如何在Node.js Express服务中的查询参数中发送整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的盒子上运行着一个nodejs express Web服务器.我想发送一个get请求以及查询参数.有什么办法可以找到每个查询参数的类型,例如int,bool,string.查询参数键值对我来说是未知的.我在服务器端将其解释为键值对的json对象.

I have a nodejs express web server running on my box. I want to send a get request along with query parameters. Is there any way to find type of each query parameter like int,bool,string. The query parameters key value is not know to me. I interpret as a json object of key value pairs at server side.

推荐答案

您不能这样做,因为HTTP没有类型的概念:所有内容都是字符串,包括查询字符串参数.

You can't, as HTTP has no notion of types: everything is a string, including querystring parameters.

您需要做的是使用 req.query对象并将字符串手动转换为使用 parseInt()

What you'll need to do is to use the req.query object and manually transform the strings into integers using parseInt():

req.query.someProperty = parseInt(req.query.someProperty);

这篇关于如何在Node.js Express服务中的查询参数中发送整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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