bugfix 修复'[]'格式json解析错误问题 (#1242)
https://github.com/metersphere/metersphere/issues/1144 Co-authored-by: zhouyx <zhouyx1@guahao.com>
This commit is contained in:
parent
764ee6507e
commit
fed842e442
|
@ -1,30 +1,23 @@
|
||||||
package io.metersphere.commons.utils;
|
package io.metersphere.commons.utils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import com.alibaba.fastjson.JSON;
|
||||||
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.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.alibaba.fastjson.JSONPath;
|
import com.alibaba.fastjson.JSONPath;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class JsonPathUtils {
|
public class JsonPathUtils {
|
||||||
|
|
||||||
public static List<HashMap> getListJson(String jsonString) {
|
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<>();
|
List<HashMap> allJsons =new ArrayList<>();
|
||||||
|
|
||||||
// 获取到所有jsonpath后,获取所有的key
|
// 获取到所有jsonpath后,获取所有的key
|
||||||
List<String> jsonPaths = JSONPath.paths(jsonObject).keySet()
|
List<String> jsonPaths = new ArrayList<>(JSONPath.paths(jsonObject).keySet());
|
||||||
.stream()
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
//去掉根节点key
|
//去掉根节点key
|
||||||
List<String> parentNode = new ArrayList<>();
|
List<String> parentNode = new ArrayList<>();
|
||||||
//根节点key
|
//根节点key
|
||||||
|
|
Loading…
Reference in New Issue