Javascript 从http响应体获取特定值
我无法从http响应体获取该值 我在response.body上使用了Javascript 从http响应体获取特定值,javascript,node.js,json,xmlhttprequest,Javascript,Node.js,Json,Xmlhttprequest,我无法从http响应体获取该值 我在response.body上使用了JSON.parse(),还使用了xmljs库。我必须得到的值是“P01”。 以下是回应: { "Soap:Envelope":{ "_attributes":{ "xmlns:Soap":"http://schemas.xmlsoap.org/soap/envelope/" },
JSON.parse()
,还使用了xmljs
库。我必须得到的值是“P01
”。
以下是回应:
{
"Soap:Envelope":{
"_attributes":{
"xmlns:Soap":"http://schemas.xmlsoap.org/soap/envelope/"
},
"Soap:Body":{
"ValidateUser_Result":{
"_attributes":{
"xmlns":"urn:microsoft-dynamics-schemas/codeunit/UserValidation"
},
"return_value":{
"_text":"P01"
}
}
}
}
}
以下是我尝试过的:
console.log(JSON.parse(data["Soap:Envelope"]["Soap:Body"]["ValidateUser_Result"]["return_value"])));
这样就行了
const data={
“Soap:信封”:{
“_属性”:{
“xmlns:Soap”:”http://schemas.xmlsoap.org/soap/envelope/"
},
“Soap:正文”:{
“ValidateUser_结果”:{
“_属性”:{
“xmlns”:“urn:microsoft dynamics架构/codeunit/UserValidation”
},
“返回值”:{
“_text”:“P01”
}
}
}
}
}
日志(数据[“Soap:Envelope”][“Soap:Body”][“ValidateUser_Result”][“return_value”][“_text”])
你能发布你尝试过的东西吗?响应[“Soap:Envelope”][“Soap:Body”]。验证用户结果。返回值
edit:fixedIt是一个Javascript对象,而不是JSON。如果您需要知道如何从中获取值,请参阅任何面向初学者的Javascript教程,例如。应该注意,上面的代码片段显示了Javascript对象文字。JSON是一种文本格式。没有JSON对象这样的东西。
var o = {
"Soap:Envelope":{
"_attributes":{
"xmlns:Soap":"http://schemas.xmlsoap.org/soap/envelope/"
},
"Soap:Body":{
"ValidateUser_Result":{
"_attributes":{
"xmlns":"urn:microsoft-dynamics-schemas/codeunit/UserValidation"
},
"return_value":{
"_text":"P01"
}
}
}
}
};
var val = o['Soap:Envelope']['Soap:Body']['ValidateUser_Result']['return_value']['_text'];
console.log(val);