javascript - 不要读取node.js中的JSON对象

标签 javascript jquery json ajax node.js

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

我将 json 对象发送到 localhost(node.js 服务器)。

当node.js服务器收到json对象时,解析出的json对象有'undefined 类型。

因此,我检查了 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": []
  }
}

最佳答案

@jeremy-thille 已经回答了问题,但为了更清楚,只需更改

dataType: "text"

dataType: "json"

并删除 JSON.stringify 调用......

关于javascript - 不要读取node.js中的JSON对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37749274/

相关文章:

c# - 在 asp.net mvc c# 中将钱格式化为货币

ios - 如何对 JSON 数组进行排序并将其呈现在 UITableView 中

javascript - jQuery 中的 .not() 函数

coldfusion - 为动态内容创建动态 jQuery 工具提示

json - 在 cloudformation 中的 yaml 内的 json 中使用 Fn::ImportValue

javascript - this.myObj = myObj 会存储引用或副本/快照吗?

javascript - 使用 Reactjs Stripe 自定义表单

javascript - "Objects are not valid as a React Child"进口

javascript - SlideToggle() 不会将使用 jquery append() 创建的元素向下推

javascript - 如何在 Google Sheet 中找到完整删除的脚本?