若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轉換形式。