简体   繁体   中英

Getting specific value from http response body

I can not get the value from an http response body.

I've used JSON.parse() on the response.body I get as well as xml-js library. The value I have to get is ' P01 '. This is the response:

{  
   "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"
            }
         }
      }
    }
}

and here is what I've tried:

console.log(JSON.parse(data["Soap:Envelope"]["Soap:Body"]["ValidateUser_Result"]["return_value"])));
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);

This will do the trick.

 const data = { "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(data["Soap:Envelope"]["Soap:Body"]["ValidateUser_Result"]["return_value"]["_text"]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM