I have seen many forum questions about this, but i haven't found a solution that works for me. THis is my code:
String serviceURL = "http://www.mywebsite.com/WebService.asmx";
String serviceNamespace = "http://tempuri.org/";
String serviceMethod = "getUser";
String SoapAction = "http://tempuri.org/getUser";
SoapObject SoapObj = new SoapObject(serviceNamespace,serviceMethod);
SoapObj.newInstance ();
SoapObj.addProperty ("uname", "Evv");
// SoapObj.addProperty ("uposy", "333");
//SoapObj.addProperty ("uposx", "333");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = SoapObj;
envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.encodingStyle = "utf-8";
envelope.enc = SoapSerializationEnvelope.ENC2001;
envelope.xsd = SoapEnvelope.XSD;
envelope.xsi = SoapEnvelope.XSI;
AndroidHttpTransport ht = new AndroidHttpTransport(serviceURL);
//Initiate Connection
try
{
ht.debug = true;
ht.call (SoapAction, envelope);
SoapObject response=(SoapObject)envelope.getResponse();
tv.setText(response);
}
Is the anyType{uposx=222; uposy=222;} a JSON-response? I can see it written out in the textview, but i want to parse it.
I have tried with JSON Object, but not gotten it to work:
JSONObject JSONObj;
JSONArray JSONArr;
SoapObject res = (SoapObject)envelope.getResponse();
gets our result in JSON String
String ResultObject = response.getProperty(0).toString();
if (ResultObject.startsWith("anyType{")) { // if JSON string is an object
JSONObj = new JSONObject(ResultObject);
Iterator<String> itr = JSONObj.keys();
while (itr.hasNext()) {
String Key = (String) itr.next();
String Value = JSONObj.getString(Key);
bundleResult.putString(Key, Value);
tv.setText(bundleResult.getString(Key));
}
} else if (ResultObject.startsWith("anyType{")) { // if JSON string is an array
JSONArr = new JSONArray(ResultObject);
tv.setText("length" + JSONArr.length());
for (int i = 0; i < JSONArr.length(); i++) {
JSONObj = (JSONObject) JSONArr.get(i);
bundleResult.putString(String.valueOf(i), JSONObj.toString());
// System.out.println(bundleResult.getString(i));
}
}
Thanks for any help!