String urlData = "data=data10&name=&sensor=sensor10&type=type10";
String data = null;
try {
data = URLDecoder.decode(urlData, "UTF-8");
}catch (Exception e){
log.error("解码失败:{}", e);
}
Map<String, Object> collect = Arrays.stream(data.split("&"))
.map(str -> str.split("="))
.collect(Collectors.toMap(x -> x[0], x -> x.length == 2 ? x[1] : "",
(u, v) -> {
throw new IllegalStateException(String.format("Duplicate key %s", u));
}, LinkedHashMap::new));
JSONObject dataJSON = new JSONObject(collect);
System.out.println(dataJSON);
JAVA将URL地址参数转JSON
于 2023-10-20 17:54:10 首次发布