我在Android代码中调用Web服务时遇到问题。我的web service code返回一个字符串,中间有一个分隔符'#'。现在我需要在Android中创建一个代码来调用Web服务,将分隔符分开,以便使用复选框显示实际名称以供用户选择
这是我的Android代码:
package com.app;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.TextView;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
public class TestApp extends Activity {
private static final String SOAP_ACTION = "http://tempuri.org/getData";
private static final String METHOD_NAME = "getData";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://10.0.2.2/login2/Service1.asmx";
TextView tv;
boolean[] bln1=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv=(TextView)findViewById(R.id.text1);
call();
String[] arr={""};
boolean[] bln = {false, false, false};
bln1 = new boolean[arr.length];
new AlertDialog.Builder(TestApp.this)
.setIcon(R.drawable.alert_dialog_icon)
.setTitle("Title")
.setMultiChoiceItems(arr,
bln,
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int whichButton,
boolean isChecked) {
if(isChecked){
bln1[whichButton] = true;
}
else{
bln1[whichButton] = false;
}
}
})
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.show();
}
public void call()
{
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//request.addProperty("passonString", "Hello Android");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
Object result = (Object)envelope.getResponse();
tv.setText(result.toString());
} catch (Exception e) {
tv.setText(e.getMessage());
}
}
}
答案 0 :(得分:1)
而不是套管到对象Object result = (Object)envelope.getResponse();
施放
SoapPrimitive responsesData = (SoapPrimitive) envelopes.getResponse();
String result = responsesData .toString();