import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; public static void main(String[] args) { String str = "[{\"url\":\"cmsapi/uploadFile/cms/content/1652891041178.png\",\"name\":\"logo.png\",\"path\":\"/uploadFile/cms/content/1652891041178.png\",\"uid\":1652891040861,\"status\":\"success\"}]"; // path /* JSONObject jsonObject = JSONObject.parseObject(str); Object name = jsonObject.get("name"); System.out.println("name = " + name);*/ // JSONObject jsonObject = JSON.parseObject(str); // Object path = jsonObject.get("path"); // System.out.println("path = " + path); JSONArray jsonArray = JSONUtil.parseArray(str); Object url = ((JSONObject) jsonArray.get(0)).get("path"); String s = url.toString(); System.out.println("url = " + s); }
标签:name,get,url,JSONObject,JSON,str,数组,path,属性 From: https://www.cnblogs.com/wanglichaoya/p/17266168.html