1.json格式的字符串 转JSONObject publicstaticvoidmyJson(Stringstr){JSONObjectobj=JSON.parseObject(str);// 测试结果System.out.println(obj);} 2.json格式的字符串 转JSONArray publicstaticvoidmyJson(Stringstr){JSONArrayarray=JSON.parseArray(str);// 测试结果for(Objectobject:array){JSONObjectobj=(JSON...
使用json-lib。JSONObject ja = JSONObject.fromObject(jsonstring)
[{"name":"zhangsan","value":21},{"name":"lisi","value":18},{"name":"wangwu","value":32}] 在这个例子中,json将users数组对象转化为json字符串输出了
String jsonString = JSONArray.toJSONString(list); System.out.println(jsonString);//[{"age":20,"id":1,"name":"张三"},{"age":19,"id":2,"name":"李四"},{"age":18,"id":3,"name":"王五"}] //把json格式字符串转换成java集合对象 List<Student> studentList = JSONArray.parseArray(j...
java中JSON将数组对象转换成JSON字符串输出实例先上代码和结果 [java]1. import java.util.ArrayList;2. import java.util.HashMap;3. import java.util.Map;4.5. import net.sf.json.JSONArray;6.7. public class TestJsonObject { 8.9. public static void main(String args[]){ 10. ArrayList ...