import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public static void main(String[] args) {
List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("a", "b");
map.put("b", "c");
list.add(map);
String arrStr = JSONArray.fromObject(list).toString();//list转String
String objStr = JSONObject.fromObject(map).toString();//map转String
System.out.println(arrStr);//[{"b":"c","a":"b"}]
System.out.println(objStr);//{"b":"c","a":"b"}
JSONArray arr = JSONArray.fromObject(arrStr);
List<Map<String, Object>> list1 = JSONArray.fromObject(arrStr);
JSONObject obj = JSONObject.fromObject(objStr);
Map<String, Object> map1 = JSONObject.fromObject(objStr);
}

posted on 2017-12-27 15:53  来临  阅读(1181)  评论(0编辑  收藏  举报