node.js官网小例子运行不起来
发布于 8 年前 作者 weiheli 5671 次浏览 来自 问答

我的 node 版本是 5.0.0

下面是从官网 https://nodejs.org/api/querystring.html 中摘抄下搂的代码:

  var querystring = require('querystring')

  var queryString = querystring.stringify({ w: '中文', foo: 'bar' }, null, null, {encodeURIComponent: gbkEncodeURIComponent})
  console.log(queryString)

运行之后,报错信息如下:

WeiHeLi:node weiheli$ node 001.js 
/Users/weiheli/code/node/001.js:3
var queryString = querystring.stringify({ w: '中文', foo: 'bar' }, null, null, {encodeURIComponent: gbkEncodeURIComponent})
																								  ^

ReferenceError: gbkEncodeURIComponent is not defined
	at Object.<anonymous> (/Users/weiheli/code/node/001.js:3:99)
	at Module._compile (module.js:425:26)
	at Object.Module._extensions..js (module.js:432:10)
	at Module.load (module.js:356:32)
	at Function.Module._load (module.js:311:12)
	at Function.Module.runMain (module.js:457:10)
	at startup (node.js:136:18)
	at node.js:972:3

哪里错了?

3 回复

看来你没看注释啊: // Suppose gbkDecodeURIComponent function already exists, // it can decode gbk encoding string

至于gbkDecodeURIComponent在哪,我也不知道,自己找吧。

@pluswave 我的错,我傻

回到顶部