JSON 数组对象获取 其中某个属性的值

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

    }

 


posted @ 2023-03-28 17:51  消失的那两年  阅读(817)  评论(0)    收藏  举报