[英]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>
想解析以上响应中的项目json
使用以下代码获取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())
将肥皂响应作为字符串传递给$()
,您将获得一个jQuery对象并对其进行迭代以获取响应文本。 然后将该值传递给JSON.parse()
以获取响应。
提琴与响应文本解析为javascript对象并打印在控制台上。 http://jsfiddle.net/aedne4os/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.