我正在尝试使用 kSOAP2 将字符串数组从 Web 服务发送到 android 应用程序。使用 kSOAP2,我在 android 端收到对象格式的响应。现在我想将此对象转换为字符串数组格式,以便我可以将此数组直接传递给 GridView。
我的Web服务方法如下:
[WebMethod]
public string[] getit(string status)
{
string[] result;
if (status == "blue")
result = new string[] { "One", "Two", "Three", "Four" };
else
result = new string[] { "five", "six", "Seven", "Eight" };
return result;
}
我的安卓代码如下:
public void call(String status)
{
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("status",status.toString());
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();
array1=(String []) result; //This statement does not work
}
}
在 android 代码中,array1 是全局声明的字符串数组。字符串数组1[]; 我想将 Object 结果转换为 array1 String 数组。提前致谢。