[英]Node.js: Not able to extract querystring value
With node.js 使用node.js
Code: 码:
var querystring = require('querystring');
...
console.log("Incoming: ", event);
var output = querystring.parse(event);
console.log("Key 1 value is: ", output.key1);
Output: 输出:
Incoming: { key3: 'value 3', key2: 'value 2', key1: 'value 3' }
Key 1 value is: undefined
Why is the Key1 value printed as undefined (although incoming event is printed correctly just before that)? 为什么将Key1值打印为未定义(尽管在此之前正确打印了传入事件)?
Your event
object isn't a querystring, so there isn't anything to parse in this case. 您的event
对象不是查询字符串,因此在这种情况下没有任何要解析的内容。
querystring
is for parsing raw HTTP query strings: querystring
用于解析原始HTTP查询字符串:
var qs = require('querystring');
var parsed = qs.parse("key1=value3&key2=value2&key3=value1");
// { key1: 'value3', key2: 'value2', key3: 'value1' }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.