Commit 2d700e466811aa1f2255d7635221f1c23d27f432

Authored by hujiaqi
1 parent b285df1f63

添加了一个处理单层map的工具类

Showing 1 changed file with 25 additions and 1 deletions

platform-common/src/main/java/com/lyms/platform/common/utils/JsonUtil.java View file @ 2d700e4
... ... @@ -132,6 +132,30 @@
132 132  
133 133 /**
134 134 * @auther HuJiaqi
  135 + * @createTime 2016年12月12日 15时47分
  136 + * @discription 获取map,处理总产程类似使用-"{\"h\":5,\"m\":0}",不按规则使用则返回null
  137 + */
  138 + public static Map<String, String> getMap(String str) {
  139 + if (StringUtils.isEmpty(str)) {
  140 + return null;
  141 + }
  142 + try {
  143 + HashMap<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 + String value = jsonObject.get(key).toString();
  149 + data.put(key, value);
  150 + }
  151 + return data;
  152 + } catch (Exception e) {
  153 + return null;
  154 + }
  155 + }
  156 +
  157 + /**
  158 + * @auther HuJiaqi
135 159 * @createTime 2016年12月12日 15时11分
136 160 * @discription 获取双层map,处理产程类似使用-"{\"one\":{},\"two\":{},\"three\":{\"h\":55,\"m\":5}}",不按规则使用则返回null
137 161 */
... ... @@ -150,7 +174,7 @@
150 174 Map<String, String> value = new HashMap<>();
151 175 while (it1.hasNext()) {
152 176 String key1 = String.valueOf(it1.next());
153   - String value1 = jsonObject1.get(key1) == null ? "" : jsonObject1.get(key1).toString();
  177 + String value1 = jsonObject1.get(key1).toString();
154 178 value.put(key1, value1);
155 179 }
156 180 data.put(key, value);