package com.huacai.wap.utils; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import net.sf.json.JSONObject; public class JsonUtils { /** */ /** * 從json HASH表達(dá)式中獲取一個(gè)map,改map支持嵌套功能 * * @param jsonString * @return */ public static Map getMap4Json(String jsonString) { JSONObject jsonObject = JSONObject.fromObject(jsonString); Iterator keyIter = jsonObject.keys(); String key; Object value; Map valueMap = new HashMap(); while (keyIter.hasNext()) { key = (String) keyIter.next(); value = jsonObject.get(key); valueMap.put(key, value); } return valueMap; } public static String getJsonStrFromObj(Object obj) { JSONObject jonObject =JSONObject.fromObject(obj); return jonObject.toString(); } } |
|
來(lái)自: CevenCheng > 《常用功能組件》