日期:2014-05-16  浏览次数:20406 次

json 转换为map

public static void main(String[] args) {
??? ??? String jsonData = "{'name':'yang','age':2}";
??? ??? Map<String,String> map = parseData(jsonData);
??? ??? System.out.println(map.get("name"));
??? }

??? /**
??? ?*
??? ?* 函数名称: parseData
??? ?* 函数描述: 将json字符串转换为map
??? ?* @param data
??? ?* @return
??? ?*/
??? private static Map<String, String> parseData(String data){
??? ??? GsonBuilder gb = new GsonBuilder();
??????? Gson g = gb.create();
??????? Map<String, String> map = g.fromJson(data, new TypeToken<Map<String, String>>() {}.getType());
??? ??? return map;
??? }