解决方案 »
- 《浮动搜索框》看的我眼睛都花了,到底哪错了。
- 求高手.ListView中Position问题!
- 麦克风能共享吗?
- 有没有前辈能说清vnd.android.cursor.item的
- 关于JNI 的问题(所有都编译好运行后提示找不到方法)
- Webview 问题////
- 使用堆栈管理activity,第二次启动时进入程序黑屏?
- 目前有一个需求,在android系统中内置指定的第三方apk,要求apk能够被用户通过android系统自带的卸载功能卸载。哪位大侠能够帮帮忙! 非常感谢!!
- openfire如何整合不同的用户系统
- popupWindow 弹出另一个PopupWindow出现问题,求大神帮忙,不盛感激
- 开发工具推荐哪个?
- ListView 异步加载图片时遇到的问题
如果好用的话,40分感觉有点少了吧,自主研发的哦。
package lib;import java.util.ArrayList;
import java.util.HashMap;import org.ksoap2.serialization.AttributeInfo;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;public class DataParser {
/**
* DataSet 解析 HashMap, 仅支持含一张表的 DataSet
* @param soapObject
* @return
*/
public static ArrayList<HashMap<String, String>> parseDataSet(SoapObject soapObject){
ArrayList<HashMap<String, String>> res = new ArrayList<HashMap<String,String>>();
ArrayList<String> level=new ArrayList<String>();
processSoapObjectTableRow = null;
processSoapObjectColumnType = null;
ProcessSoapObject(res, level, soapObject);
return res;
} /**
* 临时表名
*/
private static String processSoapObjectTablename = "";
/**
* 临时行对象
*/
private static HashMap<String, String> processSoapObjectTableRow = null;
/**
* 字段名及字段类型
*/
private static HashMap<String, String> processSoapObjectColumnType = null;
/**
* DataSet 解析 HashMap 子函数, 递归调用
* @param res
* @param level
* @param soapObject
*/
private static void ProcessSoapObject(ArrayList<HashMap<String, String>> res,
ArrayList<String> level, SoapObject soapObject) {
HashMap<String, String> attrval = GetAttributes(soapObject);
if (soapObject.getPropertyCount() == 0) {
if( processSoapObjectColumnType != null
&& "element".equals(getLevel(level, -1))
&& "sequence".equals(getLevel(level, -2))
&& "complexType".equals(getLevel(level, -3)) ){
processSoapObjectColumnType.put(attrval.get("name"), attrval.get("type"));
}
} else {
if("element".equals(getLevel(level,-1))
&& "choice".equals(getLevel(level,-2))
&& "complexType".equals(getLevel(level,-3))
&& "element".equals(getLevel(level,-4))
&& "schema".equals(getLevel(level,-5)) ){
processSoapObjectTablename = attrval.get("name");
processSoapObjectColumnType = new HashMap<String, String>();
}
PropertyInfo pi = new PropertyInfo();
for (int i = 0; i < soapObject.getPropertyCount(); i++) {
soapObject.getPropertyInfo(i, pi);
String name = pi.name;
Object obj = soapObject.getProperty(i);
if (obj instanceof SoapObject) {
level.add(name);
if( name.equals(processSoapObjectTablename)
&& ( "NewDataSet".equals(getLevel(level, -2)) || "DocumentElement".equals(getLevel(level, -2)))
&& "diffgram".equals(getLevel(level, -3)) ){
processSoapObjectTableRow = new HashMap<String, String>();
res.add(processSoapObjectTableRow);
ProcessSoapObject(res, level, (SoapObject) obj);
processSoapObjectTableRow = null;
}
else{
ProcessSoapObject(res, level, (SoapObject) obj);
}
level.remove(level.size()-1);
}
else{
if( processSoapObjectTableRow != null
&& processSoapObjectTablename.equals(getLevel(level, -1))){
String fieldname = name.toUpperCase();
String valtype = processSoapObjectColumnType==null? null : processSoapObjectColumnType.get(name);
if("xs:boolean".equals(valtype)){
processSoapObjectTableRow.put(fieldname, "" + obj);
}
else if("xs:dateTime".equals(valtype)){
//String tmp = ("" + obj).replace("T", " ");
//processSoapObjectTableRow.put(fieldname, tmp);
processSoapObjectTableRow.put(fieldname, "" + obj);
}
else{
processSoapObjectTableRow.put(fieldname, "" + obj);
}
}
}
}
}
} private static String getLevel(ArrayList<String> level, int offset) {
int i = level.size() + offset;
if(i>=0 && i<level.size()){
return level.get(i);
}
return "";
} private static HashMap<String, String> GetAttributes(SoapObject soapObject) {
HashMap<String, String> res=new HashMap<String, String>();
AttributeInfo ai = new AttributeInfo();
for(int i=0; i<soapObject.getAttributeCount(); i++){
soapObject.getAttributeInfo(i, ai);
res.put(ai.name, "" + soapObject.getAttribute(i));
}
return res;
}
}