简体   繁体   中英

Unable to parse json data from responseText of Soap Response in Jquery Mobile

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <ValidateUserResponse xmlns="http://tempuri.org/">
            <ValidateUserResult>{"Items":{"Success":"1","UserId":"3","msg":"Success"}}</ValidateUserResult>
        </ValidateUserResponse>
    </soap:Body>
</soap:Envelope>

want to parse items json from above response

use the following code to get a javascript object;

JSON.parse($('<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><ValidateUserResponse xmlns="http://tempuri.org/"><ValidateUserResult>{"Items":{"Success":"1","UserId":"3","msg":"Success"}}</ValidateUserResult></ValidateUserResponse></soap:Body></soap:Envelope>').children().find('validateuserresult').text())

pass the soap response as a string to $() and you will get a jQuery object and iterate it to get to the response text. then pass that value into JSON.parse() to get the response.

Fiddle with response text parsed to a javascript object and printed on console. http://jsfiddle.net/aedne4os/

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