获取格式化后的值 @param sourchJson @param key @return
(String sourchJson, String key)
| 163 | * @return |
| 164 | */ |
| 165 | private String getBuildValue(String sourchJson, String key) { |
| 166 | key = key.trim(); |
| 167 | Matcher funMatch = funPattern.matcher(key); |
| 168 | if (key.startsWith("$.")) {// jsonpath |
| 169 | key = JSONPath.read(sourchJson, key).toString(); |
| 170 | } else if (funMatch.find()) { |
| 171 | // String args; |
| 172 | // if (funMatch.group(2).startsWith("$.")) { |
| 173 | // args = JSONPath.read(sourchJson, funMatch.group(2)).toString(); |
| 174 | // } else { |
| 175 | // args = funMatch.group(2); |
| 176 | // } |
| 177 | String args = funMatch.group(2); |
| 178 | String[] argArr = args.split(","); |
| 179 | for (int index = 0; index < argArr.length; index++) { |
| 180 | String arg = argArr[index]; |
| 181 | if (arg.startsWith("$.")) { |
| 182 | argArr[index] = JSONPath.read(sourchJson, arg).toString(); |
| 183 | } |
| 184 | } |
| 185 | String value = FunctionUtil.getValue(funMatch.group(1), argArr); |
| 186 | key = StringUtil.replaceFirst(key, funMatch.group(), value); |
| 187 | |
| 188 | } |
| 189 | return key; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * 提取json串中的值保存至公共池中 |
no test coverage detected