Commit 34422fa6f353f30c25be083c2528480fe9339034
1 parent
cfc41c0e86
Exists in
master
and in
8 other branches
添加了一个处理双层map的工具类
Showing 1 changed file with 31 additions and 3 deletions
platform-common/src/main/java/com/lyms/platform/common/utils/JsonUtil.java
View file @
34422fa
... | ... | @@ -6,14 +6,11 @@ |
6 | 6 | import com.lyms.platform.common.pojo.SyncDataModel; |
7 | 7 | import net.sf.json.JSONArray; |
8 | 8 | import net.sf.json.JSONObject; |
9 | -import net.sf.json.JsonConfig; | |
10 | -import net.sf.json.processors.JsDateJsonValueProcessor; | |
11 | 9 | import org.apache.commons.lang.StringUtils; |
12 | 10 | import org.codehaus.jackson.map.ObjectMapper; |
13 | 11 | import org.springframework.data.mongodb.core.query.Update; |
14 | 12 | |
15 | 13 | import java.io.IOException; |
16 | -import java.sql.Timestamp; | |
17 | 14 | import java.util.*; |
18 | 15 | |
19 | 16 | public class JsonUtil { |
... | ... | @@ -131,6 +128,37 @@ |
131 | 128 | System.out.println(JsonUtil.obj2JsonString(update)); |
132 | 129 | System.out.println(JsonUtil.obj2Str(update)); |
133 | 130 | |
131 | + } | |
132 | + | |
133 | + /** | |
134 | + * @auther HuJiaqi | |
135 | + * @createTime 2016年12月12日 15时11分 | |
136 | + * @discription 获取双层map,处理产程类似使用-"{\"one\":{},\"two\":{},\"three\":{\"h\":55,\"m\":5}}",不按规则使用则返回null | |
137 | + */ | |
138 | + public static Map<String, Map<String, String>> getDoubleMap(String str) { | |
139 | + if (StringUtils.isEmpty(str)) { | |
140 | + return null; | |
141 | + } | |
142 | + try { | |
143 | + Map<String, Map<String, String>> data = new HashMap<>(); | |
144 | + JSONObject jsonObject = JSONObject.fromObject(str); | |
145 | + Iterator it = jsonObject.keys(); | |
146 | + while (it.hasNext()) { | |
147 | + String key = String.valueOf(it.next()); | |
148 | + JSONObject jsonObject1 = JSONObject.fromObject(jsonObject.get(key)); | |
149 | + Iterator it1 = jsonObject1.keys(); | |
150 | + Map<String, String> value = new HashMap<>(); | |
151 | + while (it1.hasNext()) { | |
152 | + String key1 = String.valueOf(it1.next()); | |
153 | + String value1 = jsonObject1.get(key1) == null ? "" : jsonObject1.get(key1).toString(); | |
154 | + value.put(key1, value1); | |
155 | + } | |
156 | + data.put(key, value); | |
157 | + } | |
158 | + return data; | |
159 | + } catch (Exception e) { | |
160 | + return null; | |
161 | + } | |
134 | 162 | } |
135 | 163 | |
136 | 164 | } |