取object对像中的数据

来源:互联网 发布:qq飞车沙皇数据 编辑:程序博客网 时间:2024/05/16 05:55
若Object是List集合List<Object> resultList = mdmWritebackDao.getEsolutionCallData(esolutionCall, indexOf, pageSize);
for (Object obj : resultList) {Object[] objs = (Object[]) obj;String param1 = (String) objs[0];        String param2 = (String) objs[1];String param3 = (String) objs[2];   }

若Object数据是数组形式的,eg:

[{id=f25738c6547688470154cd6bc2d50002, title=1000日儿科幻灯片}, {id=f25738c6547688470154cd6bc2d50002, title=1000日儿科幻灯片}, {id=f25738c6547688470154cd6bc2d50002, title=1000日儿科幻灯片}]
首先用JSONArray进行数据转换,结果

net.sf.json.JSONArray$JSONArrayListIterator@294398db

变成了数组对像,然后迭代每个数组元素,当迭代第一个数据时,eg

{id=f25738c6547688470154cd6bc2d50002, title=1000日儿科幻灯片}

再用JSONObject转换,最后获取数据。

完整代码如下:

                Object object = param.get("dataList");net.sf.json.JSONArray ja = net.sf.json.JSONArray.fromObject(object);@SuppressWarnings("rawtypes")Iterator iterator = ja.iterator();while(iterator.hasNext()){      Object next = iterator.next();    JSONObject jaC = net.sf.json.JSONObject.fromObject(next);    String docId = (String) jaC.get("id");    String docTitle = (String) jaC.get("title");}
根据数据的样式选择合适的json转换形式。


0 0