Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从http响应体获取特定值_Javascript_Node.js_Json_Xmlhttprequest - Fatal编程技术网

Javascript 从http响应体获取特定值

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/" },

我无法从http响应体获取该值

我在response.body上使用了
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);