我有一个名为ionList的列表,其中有名为structs的值。列表中的每个结构都有更多的列表,而这些列表中还有更多的结构。您可以想象它像父级列表和子级列表
我想完全检索ionList中的所有结构并将其存储在一个名为StructList的列表中。
我使用的代码是递归代码,但是当我在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循环初始化,我认为这是不解析其中一个带有子列表的结构的原因。请帮帮我..
这行说
ionChildList = (IonList) ionStructList.get(index).get(childList);
应该说
ionChildList = (IonList)((IonStruct) ionList.get(index)).get(childList);
因为在中ionStructList
,索引会有所不同,因此对于您的代码,您将不会检索正确的列表。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句