【问题标题】:Android: Can't parse null values from SOAP response (kSoap2)Android:无法解析来自 SOAP 响应 (kSoap2) 的空值
【发布时间】:2011-04-20 08:12:16
【问题描述】:

将 SoapObject 数据解析为 String[] 时,来自 web 服务的响应中的空字段不会添加到其中,并且我无法通过检查 null 或“”来识别空属性。

所以我的问题基本上是:SoapObject 包含正确数量的属性,但解析结果 (String[]) 不包含那些为空的,我也无法检查空属性并将“”添加到字符串[]。

当我保存到 SQLite DB 时,这会给我带来问题,因为每个例如“用户”包含不同数量的字段。

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;
}

这真的让我很头疼,我很感激能得到任何帮助:)

【问题讨论】:

    标签: android parsing soap null


    【解决方案1】:

    我需要检查“AnyType{}”:)

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

    刚刚在 else if 下面添加了这段代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-22
      • 1970-01-01
      • 2015-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多