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

String 转json

String str = "{\"result\":\"success\",\"message\":\"成功!\"}";
JSONObject json = JSONObject.fromObject(str);

String 转json数组

String s="[{\"index\":0,\"fileName\":\"\",\"path\":\"\"}]";
JSONArray jsonArray = JSONArray.fromObject(s);
JSONArray jsonArray=new JSONArray();
JSONObject jsonObject=new JSONObject();
jsonObject.put("index",0);
jsonObject.put("fileName","");
jsonObject.put("path","");
jsonArray.add(jsonObject);
System.out.println(jsonArray);//[{"index":0,"fileName":"","path":""}]
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐