0
我有一些问题来获取json对象...不要阅读node.js中的JSON对象
我发送一个json对象到localhost(node.js服务器)。
当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": []
}
}
看在上帝的份上,人,停止字符串化JSON。只需使用普通的JSON数据。发送JSON,接收JSON,读取JSON。你为什么把它转换成字符串?您正尝试读取_string_的'requestInfo'属性,而不是对象。删除'JSON.stringify',完成任务。 –