From 2d700e466811aa1f2255d7635221f1c23d27f432 Mon Sep 17 00:00:00 2001 From: hujiaqi Date: Mon, 12 Dec 2016 15:49:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=8D=95=E5=B1=82map=E7=9A=84=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lyms/platform/common/utils/JsonUtil.java | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/platform-common/src/main/java/com/lyms/platform/common/utils/JsonUtil.java b/platform-common/src/main/java/com/lyms/platform/common/utils/JsonUtil.java index 040a0ae..5247eff 100644 --- a/platform-common/src/main/java/com/lyms/platform/common/utils/JsonUtil.java +++ b/platform-common/src/main/java/com/lyms/platform/common/utils/JsonUtil.java @@ -132,6 +132,30 @@ public class JsonUtil { /** * @auther HuJiaqi + * @createTime 2016年12月12日 15时47分 + * @discription 获取map,处理总产程类似使用-"{\"h\":5,\"m\":0}",不按规则使用则返回null + */ + public static Map getMap(String str) { + if (StringUtils.isEmpty(str)) { + return null; + } + try { + HashMap data = new HashMap<>(); + JSONObject jsonObject = JSONObject.fromObject(str); + Iterator it = jsonObject.keys(); + while (it.hasNext()) { + String key = String.valueOf(it.next()); + String value = jsonObject.get(key).toString(); + data.put(key, value); + } + return data; + } catch (Exception e) { + return null; + } + } + + /** + * @auther HuJiaqi * @createTime 2016年12月12日 15时11分 * @discription 获取双层map,处理产程类似使用-"{\"one\":{},\"two\":{},\"three\":{\"h\":55,\"m\":5}}",不按规则使用则返回null */ @@ -150,7 +174,7 @@ public class JsonUtil { Map value = new HashMap<>(); while (it1.hasNext()) { String key1 = String.valueOf(it1.next()); - String value1 = jsonObject1.get(key1) == null ? "" : jsonObject1.get(key1).toString(); + String value1 = jsonObject1.get(key1).toString(); value.put(key1, value1); } data.put(key, value); -- 1.8.3.1