2011-04-20 53 views
2

將SoapObject數據解析爲String []時,來自webservice的響應中的空字段不會被添加到它,並且我無法識別空的propeties通過檢查null或「」。Android:無法解析來自SOAP響應的空值(kSoap2)

所以我的問題基本上是:SoapObject包含適量的屬性,但解析結果(String [])不包含那些是空的,我也不能檢查空屬性並將「」添加到串[]。

這會導致我在保存到SQLite數據庫時出現問題, 「用戶」包含不同數量的字段。

public static String[] getStringArrayResponse(SoapObject node, Vector<String> strings) { 

    boolean isFirstCall = false; 

    if (strings == null) { 
     isFirstCall = true; 
     strings = new Vector<String>(); 
    } 

    int count = node.getPropertyCount(); 

    for (int i = 0; i < count; i++) { 

     Object obj1 = node.getProperty(i); 

     if (obj1 instanceof SoapObject) { 
      if (((SoapObject)obj1).getPropertyCount() > 0) { 
       // Returns the correct amount of properties 
       Log.d("PARSER", "propertycount = " +((SoapObject)obj1).getPropertyCount()); 
       getStringArrayResponse((SoapObject)obj1, strings); 
      } 
     } else if (obj1 instanceof SoapPrimitive) { 
      strings.add(((SoapPrimitive)obj1).toString()); 
     } 
    } 

    if (isFirstCall) { 
     return (String[])strings.toArray(new String[strings.size()]); 
    } 
    return null; 
} 

這實在讓我頭疼,我很感謝任何幫助,我可以得到:)

回答

2

我需要檢查 「ANYTYPE {}」 :)

if (obj1.toString().equals("anyType{}")){ 
    strings.add(""); 
} 

只需在else之下添加此代碼塊即可。