简体   繁体   English

无法从Jquery Mobile中的Soap Response的responseText解析json数据

[英]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 想解析以上响应中的项目json

use the following code to get a javascript object; 使用以下代码获取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())

pass the soap response as a string to $() and you will get a jQuery object and iterate it to get to the response text. 将肥皂响应作为字符串传递给$() ,您将获得一个jQuery对象并对其进行迭代以获取响应文本。 then pass that value into JSON.parse() to get the response. 然后将该值传递给JSON.parse()以获取响应。

Fiddle with response text parsed to a javascript object and printed on console. 提琴与响应文本解析为javascript对象并打印在控制台上。 http://jsfiddle.net/aedne4os/ http://jsfiddle.net/aedne4os/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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