【发布时间】: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;
}
这真的让我很头疼,我很感激能得到任何帮助:)
【问题讨论】: