使用fastjson 实现String转List、Map、JSON
直接上代码:
public static void testJSONParseArray() {//造数据Map map = new HashMap();map.put("k11", "v11");map.put("k12", "v12");List list = new ArrayList();Map map1 = new HashMap();map1.put("k21", "v21");map1.put("k22", "v22");list.add(map);list.add(map1);//把list转成JSON形式的StringString listJson = JSONObject.toJSONString(list);System.out.println(listJson);//String转成JSSONArray形式JSONArray jsonArray = JSONArray.parseArray(listJson);System.out.println(jsonArray);//用fastjson把JSON转成ListMap,借助非常好用的TypeReferenceList<Map<String,Object>> param = JSONObject.parseObject(jsonArray.toJSONString(),new TypeReference<List<Map<String,Object>>