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);
}

相关文章:

  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-26
  • 2022-02-16
猜你喜欢
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2021-09-02
  • 2021-12-17
  • 2021-08-18
  • 2022-12-23
相关资源
相似解决方案