time_tcm 2021-04-07 15:21 采纳率: 0%
浏览 77
已结题

for循环优化(6层到2层)

	private List<String> getPackageCode(String dataUcp) throws IOException {
		List<String> packageCode = new ArrayList<>();
		HashMap<String,Object> hashMap = objectMapper.readValue(dataUcp, HashMap.class);
		//遍歷map 2 3 那層
		for (Map.Entry<String, Object> stringObjectEntry : hashMap.entrySet()) {
			//獲取 2 3 那層内部
			HashMap<String,Object> value = (HashMap<String,Object>)stringObjectEntry.getValue();
			//獲取 modelRanges層
			HashMap<String,Object> rangeMaps = (HashMap<String, Object>) value.get("modelRanges");
			//遍歷 modelRanges層 獲取 地盤代號内部數據
			for (Map.Entry<String, Object> objectEntry : rangeMaps.entrySet()) {
				HashMap<String, Object> rangeValueMaps = (HashMap<String, Object>) objectEntry.getValue();
				//獲取models 層數據
				HashMap<String, Object> modelsMaps = (HashMap<String, Object>)rangeValueMaps.get("models");
				for (Map.Entry<String, Object> modelsValue : modelsMaps.entrySet()) {
					HashMap<String, Object> modelsValueMaps = (HashMap<String, Object>) modelsValue.getValue();
					//獲取transmissionVariants數據
					HashMap<String, Object> transmissionMaps = (HashMap<String, Object>) modelsValueMaps.get("transmissionVariants");
					for (Map.Entry<String, Object> transmissionValue : transmissionMaps.entrySet()) {
						HashMap<String, Object> value1 = (HashMap<String, Object>) transmissionValue.getValue();
						HashMap<String, Object> additionalData = (HashMap<String, Object>) value1.get("additionalData");
						for (Map.Entry<String, Object> additional : additionalData.entrySet()) {
							HashMap<String, Object> value2 = (HashMap<String, Object>) additional.getValue();
							HashMap<String, Object> lines = (HashMap<String, Object>) value2.get("lines");
							for (Map.Entry<String, Object> line : lines.entrySet()) {
								HashMap<String, Object> agModelMaps = (HashMap<String, Object>) line.getValue();
								String modelCode = (String) agModelMaps.get("agModelCode");
								packageCode.add(modelCode+"_"+line.getKey());
							}
						}
					}
				}
			}
		}
		return packageCode;
	}
  • 写回答

2条回答 默认 最新

  • 关注

    你要说明一下基本情况呀,如表结构之间的关系等;要不然别人都不知道情况怎么帮助你改进呢?

    评论

报告相同问题?

悬赏问题

  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错
  • ¥15 换yum源但仍然用不了httpd
  • ¥50 C# 使用DEVMOD设置打印机首选项