2013-09-25 71 views
1

一個名單上有物體從具有類似內容的PHP Web服務未來的數組:獲取從web服務陣列以及Android的

anyType[ 
objectname1{element1=1234567890; element2=test; element3=1110; element3=72.824043; }, 
objectname1{element1=11090999; element2=test; element3=2292; element3=72.824043; }] 

我使用kso​​ap2讓我的Android應用程序的Web服務數據。

我已經使用此questionchadi cortbaoui's解決方案嘗試,但它給錯誤

java.lang.ClassCastException:java.util.Vector中不能轉換到 org.ksoap2.serialization.SoapObject

爲線SoapObject response1 = (SoapObject) response.getProperty(0);用下面的代碼

envelope.encodingStyle = "UTF-8"; 
httpTransport.debug = true; 
httpTransport.call(SOAP_ACTION, envelope); 
response = (SoapObject) envelope.bodyIn; 
SoapObject response1 = (SoapObject) response.getProperty(0); 

我已經嘗試通過使用SoapPrimitive而不是SoapObject我也嘗試通過使用envelope.getResponse()代替envelope.bodyIn但它不起作用它會引發同樣的錯誤。

+1

@SamirMangroliya:怎麼是相關的?你的帖子是關於json的。這個問題不是。 – njzk2

+0

@SamirMangroliya我應該如何使用你的帖子在我的情況?如果我可以在我的問題中使用帖子,你能幫我解決嗎?我已經嘗試在你的文章中使用代碼,但它會在字符12處引發Unterminated數組的錯誤,即「=」符號在我的字符串數組中? – NetStarter

+0

@SamirMangroliya我解決了我的問題,您的鏈接也沒有幫助,因爲我作爲響應的作爲響應不是JSON字符串。多謝您的幫助。:) – NetStarter

回答

0

我用下面的代碼與此question

httpTransport.call(SOAP_ACTION, envelope); 
response = (SoapObject) envelope.bodyIn; 
Vector<?> responseVector = (Vector<?>) response.getProperty(0);//store the response object values in a Vector(It solved the vector error which i was getting 

int count=responseVector.size(); 

for (int i = 0; i <count; ++i) { //for loop for the array of the result  
SoapObject test=(SoapObject)responseVector.get(i); 
String value1 = test.getProperty("value1").toString();//get Your values from the soap object 
String value2 = test.getProperty("value2").toString(); 
String value3 = test.getProperty("value3").toString(); 
String value4 = test.getProperty("value4").toString(); 
    /*thats it now add the received values to your list using the for loop*/ 
} 

感謝的幫助下解決了我的問題。