bugfix 修复'[]'格式json解析错误问题 (#1242)

https://github.com/metersphere/metersphere/issues/1144

Co-authored-by: zhouyx <zhouyx1@guahao.com>
This commit is contained in:
Dream95 2021-01-22 18:11:38 +08:00 committed by GitHub
parent 764ee6507e
commit fed842e442
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 14 deletions

View File

@ -1,30 +1,23 @@
package io.metersphere.commons.utils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
import org.apache.commons.lang3.StringUtils;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class JsonPathUtils {
public static List<HashMap> getListJson(String jsonString) {
JSONObject jsonObject = JSONObject.parseObject(jsonString);
JSON jsonObject = jsonString.startsWith("[")?JSONObject.parseArray(jsonString):JSONObject.parseObject(jsonString);
List<HashMap> allJsons =new ArrayList<>();
// 获取到所有jsonpath后获取所有的key
List<String> jsonPaths = JSONPath.paths(jsonObject).keySet()
.stream()
.collect(Collectors.toList());
List<String> jsonPaths = new ArrayList<>(JSONPath.paths(jsonObject).keySet());
//去掉根节点key
List<String> parentNode = new ArrayList<>();
//根节点key