Javascript Don';t读取node.js中的JSON对象

Javascript Don';t读取node.js中的JSON对象,javascript,jquery,json,ajax,node.js,Javascript,Jquery,Json,Ajax,Node.js,我在获取json对象时遇到一些问题 我向localhost(node.js服务器)发送一个json对象 当node.js服务器收到json对象时,解析的json对象具有“未定义” 类型 因此,我检查了json对象,但它没有结构问题 我怎样才能解决这个问题 提前感谢 $.ajax({ url: "http://127.0.0.1:62590/saveResource", type: "post", dataType: "text", cache: false,

我在获取json对象时遇到一些问题

我向localhost(node.js服务器)发送一个json对象

当node.js服务器收到json对象时,解析的json对象具有“未定义” 类型

因此,我检查了json对象,但它没有结构问题

我怎样才能解决这个问题

提前感谢

$.ajax({
    url: "http://127.0.0.1:62590/saveResource",
    type: "post",
    dataType: "text",
    cache: false,
    timeout: 30000,
    data: JSON.stringify(jsonObject),
    success: function (data) {
       ............
    },
    error: function (xhr, textStatus, errorThrown) {
        alert(textStatus + ' : ' + errorThrown);
    }
});
===========================================================================

app.post('/saveResource', function (request, response) {

    var resultObj = request.body;
    var object = resultObj.requestInfo;
    console.log(typeof(object)); -> 'undefined' type
});
* node.js server reveceive the following object.


{
  "requestInfo": {
    "urlInformation": "data",
    "methodInformation": "GET",
    "bodyInformation": "data",
    "headerInformation": []
  }
}
===========================================================================

app.post('/saveResource', function (request, response) {

    var resultObj = request.body;
    var object = resultObj.requestInfo;
    console.log(typeof(object)); -> 'undefined' type
});
* node.js server reveceive the following object.


{
  "requestInfo": {
    "urlInformation": "data",
    "methodInformation": "GET",
    "bodyInformation": "data",
    "headerInformation": []
  }
}

@jeremy thille已经回答了这个问题,但更清楚的是,改变一下

dataType: "text"


并删除JSON.stringify调用…

@jeremy thille已经回答了这个问题,但更清楚的是,只需更改即可

dataType: "text"


并删除JSON.stringify调用…

看在上帝的份上,各位,停止stringify JSON。只需处理简单的JSON数据。发送JSON,接收JSON,读取JSON。为什么要将其转换为字符串?您试图读取的是字符串的
requestInfo
属性,而不是对象。删除
JSON.stringify
,工作完成。看在上帝的份上,各位,停止stringify JSON。只需处理简单的JSON数据。发送JSON,接收JSON,读取JSON。为什么要将其转换为字符串?您试图读取的是字符串的
requestInfo
属性,而不是对象。删除
JSON.stringify
,工作完成。