我在获取 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/