javascript - Nodejs- TypeError : JSON. Parse,JSON.Stringify 不是函数

标签 javascript json node.js express npm

我想将字符串转换为 JSON,反之亦然。我在下面的 router.js 中使用 JSON.Stringfy。我是否需要使用 JSON.Stringfy 函数将任何特定的 npm 添加到项目中?

代码如下:

**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));
}

看到下面的异常:

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)

最佳答案

JSON.stringify 不是 JSON.Stringfy

专业提示 - 下次您在 xyz is not a function 行中看到错误消息时,请尝试使用 google 搜索该函数名称。

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

关于javascript - Nodejs- TypeError : JSON. Parse,JSON.Stringify 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33771185/

相关文章:

node.js - 在大型 Mongo 集合中,如何使用 mongoose 仅​​检索 ID(或任何其他特定属性)?

javascript - 套接字 IO 事件发射

javascript - 在文本中定位具有嵌入外部值的 java 脚本元素

javascript - Bootstrap 模态中的 Sweet Alert

javascript - 如何通过对象数组运行 forEach 并为具有空字符串的对象属性设置值?

javascript - 在一个字符串中连接对象数据

css - node.js 不会在所有页面加载 css 样式

javascript - jQuery - 我可以测试一个项目是隐藏还是显示吗?

javascript - 使用 HTML 链接 rel 导入 HTML 文档

java - Jackson databind读取json三维数组