Search code examples
androidjsonksoap2

take the json from ksoap2 response


I have an application that call a webservice and response with specific data

everything working good, but! I can't take the json array from this response

that's my response:

<?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>
        <usersGetAllManagersResponse xmlns="http://tempuri.org/">
            <usersGetAllManagersResult>[{"User_P_ID":1,"User_ID":44,"Ar_Name":"خالد","En_Name":"Khalid"}]</usersGetAllManagersResult>
        </usersGetAllManagersResponse>
    </soap:Body>
</soap:Envelope>

Solution

  • you have to parse the XML to get the content OR you can use use split()

    String resp = "<userGetAll...> ....</userGetAll...> ......";
    String parts[] = json.split("<userGetAll...>");
    parts = parts[1].split("</userGetAll...>");
    String jsonPart = parts[0];
    

    jsonPart is what you are looking for.