We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
当json数据有多层次,并且上下层关系同名时,会出现匹配不到的问题。需要修改匹配逻辑
/** * param 格式为a.b.c:xxx * map 可以去掉,获取每次的map集合 * appendMap 获取最终的map集合 * * @param param */ private void dot2Json(String param, Map map, Map appendMap) { if (null == map) { map = new HashMap<>(); } String[] o = param.split(":"); String[] split = o[0].split("\\."); // 值为空时,默认为空字符串 String content = o.length >= 2 ? o[1] : StrUtil.EMPTY; Map<String, Object> resultMap = new HashMap<>(); Map<String, Object> deepMap = appendMap; int deep = -1; for (int i = 0; i < split.length; i++) { if (i == split.length - 1) { resultMap.put(split[i], content); } else { Object obj = deepMap.get(split[i]); if (obj != null) { if (obj instanceof Map) { deepMap = (HashMap) obj; deep = i; } } resultMap.put(split[i], new HashMap<>()); } } if (split.length > 1) { for (int i = split.length - 2; i >= 0; i--) { // **这里会有问题** Map<String, Object> tempMap = (HashMap) resultMap.get(split[i]); tempMap.put(split[i + 1], resultMap.get(split[i + 1])); if (i == deep) { deepMap.put(split[i + 1], resultMap.get(split[i + 1])); } } map.put(split[0], resultMap.get(split[0])); if (-1 == deep) { deepMap.put(split[0], resultMap.get(split[0])); } } else { map = resultMap; } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
当json数据有多层次,并且上下层关系同名时,会出现匹配不到的问题。需要修改匹配逻辑
The text was updated successfully, but these errors were encountered: