[英]Nodejs- TypeError: JSON.Parse,JSON.Stringfy is not a function
I want to convert the string to JSON and vice versa. 我想将字符串转换为JSON,反之亦然。 I am using JSON.Stringfy in router.js below.
我在下面的router.js中使用JSON.Stringfy。 Do I need to have anything particular npm added to project use the JSON.Stringfy function?
我是否需要在项目中使用JSON.Stringfy函数添加任何特定的npm?
Below is the code: 以下是代码:
**app.js** file(main file executed by node.exe)
app.get('/about',routes.about);-->calling it using **http://localhost:3000/about**
**routers.js**
var User = {
'Name' :'',
'EmailId':'',
'Phone':'',
'Address':'',
'favouriteSport':''
}
exports.about = function(req,res){
res.send("Welcome to sports maniac" + JSON.Stringfy(User));
}
seeing below exception: 看到以下异常:
TypeError: JSON.Stringfy is not a function
at exports.about (F:\Personal Filess\Google Drive\Software Tools\Projects\routes\router.js:17:45)
at Layer.handle [as handle_request] (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\layer.js:95:5)
at next (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\route.js:131:13)
at Route.dispatch (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\layer.js:95:5)
at F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\index.js:277:22
at Function.process_params (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\index.js:330:12)
at next (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\index.js:271:10)
at expressInit (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\middleware\init.js:33:5)
at Layer.handle [as handle_request] (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\layer.js:95:5)
It JSON.stringify
not JSON.Stringfy
. 它
JSON.stringify
不是JSON.Stringfy
。
Pro tip - Next time you see a error message on the lines of xyz is not a function
try googling that function name. 专业提示 - 下次你看到
xyz is not a function
行上的错误消息xyz is not a function
尝试谷歌搜索该函数名称。
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
我认为你的函数名拼写错了,它是Stringify。
After a lot of research found the JSON npm module. 经过大量研究发现了JSON npm模块。 JSON2 is a npm module which is I am using.
JSON2是我正在使用的npm模块。
Just run the command in node.js command prompt :npm install json2 -g Then to add the node module to project run: npm install JSON2 --save 只需在node.js命令提示符下运行命令:npm install json2 -g然后将节点模块添加到项目运行:npm install JSON2 --save
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.