From 34422fa6f353f30c25be083c2528480fe9339034 Mon Sep 17 00:00:00 2001 From: hujiaqi Date: Mon, 12 Dec 2016 15:15:50 +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=8F=8C=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 | 34 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) 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 99e23f8..040a0ae 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 @@ -6,14 +6,11 @@ import com.lyms.platform.common.dao.operator.MongoQuery; import com.lyms.platform.common.pojo.SyncDataModel; import net.sf.json.JSONArray; import net.sf.json.JSONObject; -import net.sf.json.JsonConfig; -import net.sf.json.processors.JsDateJsonValueProcessor; import org.apache.commons.lang.StringUtils; import org.codehaus.jackson.map.ObjectMapper; import org.springframework.data.mongodb.core.query.Update; import java.io.IOException; -import java.sql.Timestamp; import java.util.*; public class JsonUtil { @@ -133,4 +130,35 @@ public class JsonUtil { } + /** + * @auther HuJiaqi + * @createTime 2016年12月12日 15时11分 + * @discription 获取双层map,处理产程类似使用-"{\"one\":{},\"two\":{},\"three\":{\"h\":55,\"m\":5}}",不按规则使用则返回null + */ + public static Map> getDoubleMap(String str) { + if (StringUtils.isEmpty(str)) { + return null; + } + try { + Map> data = new HashMap<>(); + JSONObject jsonObject = JSONObject.fromObject(str); + Iterator it = jsonObject.keys(); + while (it.hasNext()) { + String key = String.valueOf(it.next()); + JSONObject jsonObject1 = JSONObject.fromObject(jsonObject.get(key)); + Iterator it1 = jsonObject1.keys(); + Map value = new HashMap<>(); + while (it1.hasNext()) { + String key1 = String.valueOf(it1.next()); + String value1 = jsonObject1.get(key1) == null ? "" : jsonObject1.get(key1).toString(); + value.put(key1, value1); + } + data.put(key, value); + } + return data; + } catch (Exception e) { + return null; + } + } + } -- 1.8.3.1