admin管理员组文章数量:1421751
I want to convert the string to JSON and vice versa. I am using JSON.Stringfy in router.js below. Do I need to have anything particular npm added to project use the JSON.Stringfy function?
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("Wele 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)
I want to convert the string to JSON and vice versa. I am using JSON.Stringfy in router.js below. Do I need to have anything particular npm added to project use the JSON.Stringfy function?
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("Wele 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)
Share
Improve this question
edited Nov 18, 2015 at 3:57
Swaraj Giri
4,0372 gold badges30 silver badges45 bronze badges
asked Nov 18, 2015 at 3:13
Haridev NirgudeHaridev Nirgude
431 silver badge6 bronze badges
0
3 Answers
Reset to default 2ItJSON.stringify
not 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.
https://developer.mozilla/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
I think you have the function name spellt wrong, It's Stringify.
After a lot of research found the JSON npm module. JSON2 is a npm module which is I am using.
Just run the mand in node.js mand prompt :npm install json2 -g Then to add the node module to project run: npm install JSON2 --save
本文标签: javascriptNodejs TypeError JSONParseJSONStringfy is not a functionStack Overflow
版权声明:本文标题:javascript - Nodejs- TypeError: JSON.Parse,JSON.Stringfy is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745319889a2653329.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论