Javascript 无法从Jquery Mobile中Soap响应的responseText解析json数据 {“Items”:{“Success”:“1”,“UserId”:“3”,“msg”:“Success”}

Javascript 无法从Jquery Mobile中Soap响应的responseText解析json数据 {“Items”:{“Success”:“1”,“UserId”:“3”,“msg”:“Success”},javascript,jquery,jquery-mobile,Javascript,Jquery,Jquery Mobile,要解析来自上述响应的json项请使用以下代码获取javascript对象 <?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/XMLSche

要解析来自上述响应的json项

请使用以下代码获取javascript对象

<?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>
JSON.parse($('{“Items”:{“Success”:“1”,“UserId”:“3”,“msg”:“Success”}}')).children().find('validateuserresult').text())
将soap响应作为字符串传递给
$()
,您将获得一个jQuery对象并对其进行迭代以获得响应文本。然后将该值传递到
JSON.parse()
以获得响应

处理解析为javascript对象并打印在控制台上的响应文本。

你能分享你的负载函数吗?
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())