/******************************************************************************* * @project: alms * @package: com.acconsys.alms.util * @file: MapJsonUtil.java * @author: Malt * @created: 2013-9-27 * @purpose: * * @version: 1.0 * * Revision History at the end of file. * * Copyright 2013 AcconSys All rights reserved. ******************************************************************************/ package com.acconsys.alms.util; import java.util.Map; import net.sf.json.JSONObject; public class MapJsonUtil { /** * String(json) conversion Map. * @param strJSON * @return * @throws JSONException */ @SuppressWarnings("unchecked") public static Map<String,Object> StrJSON2Map(String strJSON){ JSONObject jsonObj = JSONObject.fromObject(strJSON); return (Map<String, Object>) JSONObject.toBean(jsonObj,Map.class); } /** * Map conversion String(json). * @param map * @return */ public static String MapToStrJSON(Map<String,Object> map) { String jsonStr = null; jsonStr = JSONObject.fromObject(map).toString(); return jsonStr; } public static void main(String[] args) { System.out.println(StrJSON2Map("{\"A\":\"AV\"}").get("A")); System.out.println(); System.out.println(MapToStrJSON(StrJSON2Map("{\"A\":\"AV\"}"))); } } /******************************************************************************* * <B>Revision History</B><BR> * [type 'revision' and press Alt + / to insert revision block]<BR> * * * * Copyright 2013 AcconSys All rights reserved. ******************************************************************************/
Convert between Map and Json
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326896272&siteId=291194637
Recommended
Ranking