java中将数组、对象、Map、List转换成JSON数据

2024-11-12 07:16:56

1、将数组转换为JSON: String[] arr = {"asd","dfgd","asd","234"};JSONArray jsonarray = JSONArray.fromObject(arr);System.out.println(jsonarray);

java中将数组、对象、Map、List转换成JSON数据

3、把Map转换成json, 要使用jsonObject对象: Map<String, Object> map = new HashMap<String, Object>(); map.put("userId", 1001); map.put("userName", "张三"); map.put("userSex", "男"); JSONObject jsonObject = JSONObject.fromObject(map); System.out.println(jsonObject);

java中将数组、对象、Map、List转换成JSON数据
猜你喜欢