Commit 59cc18e23f401e4185417146a3f1eb42192cd9d6
1 parent
f4723358b3
Exists in
master
and in
1 other branch
1
Showing 2 changed files with 39 additions and 7 deletions
platform-common/src/main/java/com/lyms/platform/common/utils/JsonUtil.java
View file @
59cc18e
... | ... | @@ -3,12 +3,25 @@ |
3 | 3 | import net.sf.json.JSONArray; |
4 | 4 | import net.sf.json.JSONObject; |
5 | 5 | import org.apache.commons.lang.StringUtils; |
6 | +import org.codehaus.jackson.map.ObjectMapper; | |
6 | 7 | |
8 | +import java.io.IOException; | |
7 | 9 | import java.util.*; |
8 | 10 | |
9 | 11 | public class JsonUtil { |
12 | + public static <T> T jkstr2Obj(String content, | |
13 | + Class<T> cls) { | |
14 | + ObjectMapper objectMapper = new ObjectMapper(); | |
10 | 15 | |
11 | 16 | |
17 | + try { | |
18 | + return (T) objectMapper.readValue(content, cls); | |
19 | + } catch (IOException e) { | |
20 | + e.printStackTrace(); | |
21 | + } | |
22 | + return null; | |
23 | + } | |
24 | + | |
12 | 25 | @SuppressWarnings("unchecked") |
13 | 26 | public static <T> T str2Obj(String content, |
14 | 27 | Class<T> cls) { |
15 | 28 | |
... | ... | @@ -35,10 +48,10 @@ |
35 | 48 | public static String obj2JsonString(Object obj) { |
36 | 49 | try { |
37 | 50 | return JSONObject.fromObject(obj).toString(); |
38 | - }catch (Exception e){ | |
39 | - ExceptionUtils.catchException(e,"obj2 json string error ."+e.getMessage()); | |
51 | + } catch (Exception e) { | |
52 | + ExceptionUtils.catchException(e, "obj2 json string error ." + e.getMessage()); | |
40 | 53 | } |
41 | - return null; | |
54 | + return null; | |
42 | 55 | } |
43 | 56 | |
44 | 57 | public static String array2JsonString(Object obj) { |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/result/MaternalDeliverResult.java
View file @
59cc18e
... | ... | @@ -4,7 +4,10 @@ |
4 | 4 | import com.lyms.platform.common.utils.JsonUtil; |
5 | 5 | import com.lyms.platform.pojo.BabyModel; |
6 | 6 | import com.lyms.platform.pojo.MaternalDeliverModel; |
7 | +import net.sf.ezmorph.bean.MorphDynaBean; | |
8 | +import org.codehaus.jackson.map.ObjectMapper; | |
7 | 9 | |
10 | +import java.io.IOException; | |
8 | 11 | import java.util.List; |
9 | 12 | import java.util.Map; |
10 | 13 | |
... | ... | @@ -33,7 +36,7 @@ |
33 | 36 | //手术原因 |
34 | 37 | private String operationCause; |
35 | 38 | //产程 h 小时 m 分 |
36 | - private Map prodprocess; | |
39 | + private Map<String,Map> prodprocess; | |
37 | 40 | //总产程 |
38 | 41 | private String totalprocess; |
39 | 42 | //会阴情况 |
... | ... | @@ -86,7 +89,7 @@ |
86 | 89 | setDeliveryMode(JsonUtil.str2Obj(destModel.getDeliveryMode(),Map.class)); |
87 | 90 | setOperationCause(destModel.getOperationCause()); |
88 | 91 | |
89 | - setProdprocess(JsonUtil.str2Obj(destModel.getProdprocess(),Map.class)); | |
92 | + setProdprocess(JsonUtil.jkstr2Obj(destModel.getProdprocess(),Map.class)); | |
90 | 93 | setTotalprocess(destModel.getTotalprocess()); |
91 | 94 | setPerinealCondition(destModel.getPerinealCondition()); |
92 | 95 | setSiLielevel(destModel.getSiLielevel()); |
93 | 96 | |
94 | 97 | |
... | ... | @@ -545,12 +548,28 @@ |
545 | 548 | this.ocs = ocs; |
546 | 549 | } |
547 | 550 | |
548 | - public Map getProdprocess() { | |
551 | + public Map<String, Map> getProdprocess() { | |
549 | 552 | return prodprocess; |
550 | 553 | } |
551 | 554 | |
552 | - public void setProdprocess(Map prodprocess) { | |
555 | + public void setProdprocess(Map<String, Map> prodprocess) { | |
553 | 556 | this.prodprocess = prodprocess; |
557 | + } | |
558 | + public static void main(String[] args){ | |
559 | + Map b = | |
560 | + (Map)JsonUtil.str2Obj("{\"one\":{\"h\":\"123\",\"m\":\"234\"},\"two\":{\"h\":\"123\",\"m\":\"234\"},\"three\":{\"h\":\"123\",\"m\":\"234\"}}", Map.class); | |
561 | + | |
562 | + ObjectMapper objectMapper = new ObjectMapper(); | |
563 | + | |
564 | + | |
565 | + Map acc = null; | |
566 | + try { | |
567 | + acc = objectMapper.readValue("{\"one\":{\"h\":\"123\",\"m\":\"234\"},\"two\":{\"h\":\"123\",\"m\":\"234\"},\"three\":{\"h\":\"123\",\"m\":\"234\"}}", Map.class); | |
568 | + System.out.println(acc); | |
569 | + } catch (IOException e) { | |
570 | + e.printStackTrace(); | |
571 | + } | |
572 | + System.out.print(acc); | |
554 | 573 | } |
555 | 574 | } |