[英]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.