我有一個名爲ionList的列表,其中包含名爲structs的值。 列表中的每個結構都有更多的列表,這些列表中有更多的結構。你可以想象它像一種父母名單和子列表如何從列表中獲取具有子列表的值並將所有值按順序存儲在另一個列表中
我想檢索ionList中的所有結構,並將其存儲在一個名爲StructList的列表中。
我使用的代碼是遞歸代碼,但是當我調用遞歸函數whenevr時,我遇到了我的ionList中的子列表時數據正在丟失。
public List<IonStruct> findStructsFromParentList(IonList ionList) {
String objectType = "object_type";
String diffType = "diff_type";
String childList = "children";
IonList ionChildList = null;
IonList ionChildList1 = null;
List<IonStruct> ionStructList = new ArrayList<IonStruct>();
System.out.println("ION LIST"+ionList.size());
for (int index = 0; index < ionList.size();index++) {
ionStructList.add((IonStruct) ionList.get(index));
ionChildList = (IonList) ionStructList.get(index).get(childList);
if (ionChildList != null) {
System.out.println("Found child");
ionStructList.addAll(findStructsFromParentList(ionChildList));
}
}
return ionStructList;
}
的的childList發現正在改變我對環路初始化在我的遞歸調用我認爲這是不解析一個以上的結構與它的孩子名單的原因。請幫助我..
謝謝!!!
我只是盯着這個問題,當你剛纔問了一個較長的版本。突然你刪除了它,我無法回答! :-( –
使用調試器找出for循環對所有列表項是否執行,我覺得可能會在方法findStructsFromParentList(ionChildList)中拋出一些異常 – AJJ
我也沒有刪除該帖子...我覺得它很混亂刪除它 –