我打电话在我的Android应用程序的网络服务和方法是getGramaNiladhariData(),我得到的结果作为SoapObject。
result = (SoapObject) envelope.bodyIn; Log.d("WS", String.valueOf(result));
这是我得到的将String.valueOf(结果)
getGramaNiladhariDataResponse {getGramaNiladhariDataResult = anyType的{gnName = anyType的{}; 地址= anyType的{}; workingDays = anyType的{}; gnDivision = anyType的{}; contactNumber = anyType的{}; }; }
这里我打电话回报复杂类型对象的方法,由5个的属性。 正如我在互联网上找到我不能让一个SOAP对象的Web服务方法,该方法返回一个复杂类型object.If所以,我应该怎么得到的值的结果。
我想解决的是为什么我收到anyType的{},为价值,而不是真正的价值。 任何帮助,将不胜感激
它来不及回答。 但FYI和其他人谁发现这很有用,
通过这样做String.valueOf(result)
要打印身体的全部内容。 但为了使用参数让你的价值观,首先你需要打纠正SoapObject
。
我不知道是否有找到正确的任何简单的方法SoapObject
,但还是这样做的伎俩,一旦你得到正确的SoapObject
然后你做。 在下面找到如何找到正确的SoapObject
,
首先,你需要检查则params的数量在您的第一个SoapObject
,
result.getPropertyCount();
你会得到数较少量这一点,因为这是第一个盖,
然后,打印,看看哪PARAM给你corect细节,
result.getProperty(0);
result.getProperty(1);
etc ...
一旦你找到了正确的参数,然后抢SoapObject
。 像这样,
SoapObject result2 = (SoapObject) result.getProperty(0);
然后检查此对象的数量。 做上面一样,直到你得到正确的SoapObject
。
一旦你发现了最后SoapObject
将打印像这样没有无用的字符串,
anyType{gnName = Prasad; address = Address of the person; ; workingDays = 5; gnDivision = California; contactNumber = 0123456789}
现在,您可以继续使用这个对象就是这样,
SoapObject result3 = (SoapObject) result2.getProperty(5);
Log.v("Name : ", result3.getProperty("gnName").toString());
你会得到DDMS输出像下面,
Name : Prasad
我想这会帮助你,让我知道如果您有任何进一步的问题。
我让自己的代码,我刚刚完成,现在我想用U它可以帮助一些人分享
我是工作,只有一张桌子,那就是工作,我,我会尽量解释步骤
try {
// Invole web service
androidHttpTransport.call(SOAP_ACTION + "mywebservicecall", envelope);
// Get the response
SoapObject resultsString = (SoapObject) envelope.getResponse();
//resultsString looks like this ==> anyType{schema=anyType{element=anyType{complexType=anyType{choice=anyT....etc
//here i found some complex in getproperty(0) so i not need it
//then i make Object1 that contain datatable from my database getproperty(1)
SoapObject Object1 = (SoapObject) resultsString.getProperty(1);
//object1 look like this ==> anyType{NewDataSet=anyType{Table1=anyType{ID_CAT=1; CAT_V_N=ma
//here my table1 i wanna to fitch the NewDataSet
SoapObject tables = (SoapObject) Object1.getProperty(0); //NewDataset
//tables object now looks like this ==> anyType{Table1=anyType{ID_CAT=1;CAT_N ...etc
//now i wanna loop in my table to get columns valus it will be tablesObject properties depend on iteration to get row by row
for (int i = 0; i < tables.getPropertyCount(); i++) {
SoapObject Objecttable = (SoapObject) tables.getProperty(i);
System.out.println("ID_CAT = " + Objecttable.getProperty("ID_CAT").toString());
System.out.println("CAT_N= " +Objecttable.getProperty("CAT_N").toString());
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("ID_CAT = 0 ");
System.out.println("CAT_N = None");
}
最后一个代码解释一个表
现在我只是到底是如何控制多台
我也会解释
SoapObject resultsString = (SoapObject) envelope.getResponse();
// the same
SoapObject Object1 = (SoapObject) resultsString.getProperty(1);
// the same
SoapObject tables = (SoapObject) Object1.getProperty(0);
// the same
// the same
for(int i = 0; i < tables.getPropertyCount(); i++){
SoapObject Objecttable = (SoapObject) (SoapObject) tables.getProperty(i);
try{
//tables.toString().substring(8,tables.toString().indexOf("=")).equals("Table1")
// here i was try to get the name of the table to hundel it but i fount my table name in attribute id
// it not came as table name like if my table that comming from database is hi
//the first row will be attrib=>id=>hi1 and sec row will be hi2
//the first row will be attrib=>rowOrder=>0 and sec row will be 1
if(Objecttable.getAttribute("id").equals("Table1"+(Integer.valueOf(Objecttable.getAttribute("rowOrder").toString())+1))){
// so Objecttable.getAttribute("id") will be ( "Table11" ) in first row
//Objecttable.getAttribute("rowOrder").toString() ==> will be 0
//Integer.valueOf(Objecttable.getAttribute("rowOrder").toString())+1) well be 1 for first row of this table
// so Objecttable.getAttribute("id").equals("Table1"+(Integer.valueOf(Objecttable.getAttribute("rowOrder").toString())+1)) will be true
/**
then i can loop and fitch data like single table
*/
}
if(Objecttable.getAttribute("id").equals("Table2"+(Integer.valueOf(Objecttable.getAttribute("rowOrder").toString())+1))){
}
}catch (Exception e) {
}
希望这是明确的为你们好运气
当你从网上service.Insert一个空值的一些数据,然后再尝试获取来自Web服务数据anytype类型{}来。
我以前也有这个问题。 我解决了它。 我以前也有这个问题。 我解决了它。 我似乎花了很多时间来找到解决这个问题。 我的项目是工作。 我创建Web服务.NET对象数组。 我希望这能帮到您。
//.................................
SoapObject requestx = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelopex = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelopex.dotNet = true;
envelopex.setOutputSoapObject(requestx);
HttpTransportSE httpTransportx = new HttpTransportSE(URL);
try {
httpTransportx.call(SOAP_ACTION, envelopex);
SoapObject responsex = (SoapObject)envelopex.getResponse(); // not envelopex.bodyIn;
int i=0;
int RCount=responsex.getPropertyCount();
int[] tbIDArray = new int[RCount+1];
int[] iMonthAarray = new int[RCount+1];
int[] iYearAarray = new int[RCount+1];
String[] sDetailAarray = new String[RCount+1];
for (i = 0; i < RCount; i++) {
Object property = responsex.getProperty(i);
if (property instanceof SoapObject) {
SoapObject info = (SoapObject) property;
String tbID = info.getProperty("tbID").toString();
String iMonth = info.getProperty("iMonth").toString();
String iYear = info.getProperty("iYear").toString();
String sDetail = info.getProperty("sDetail").toString();
tbIDArray[i] =Integer.valueOf(tbID);
iMonthAarray[i] =Integer.valueOf(iMonth);
iYearAarray[i] =Integer.valueOf(iYear);
sDetailAarray[i] =sDetail;
}//if (property instanceof SoapObject) {
}//for (i = 0; i < RCount; i++) {
} catch (Exception exception) {
MsgBox1(exception.toString() , "Error");
}
文章来源: SoapObject Result returns anyType{} as value when retuning a complexType object