【Java】字符串转换成Java对象

方法一

public static void main(String[] args) {
    
    
        String testParam = "{\"id\":\"1001\",\"name\":\"oowangfanoo\",\"sex\":\"30\"}";
        TestEntity testEntity = JSON.toJavaObject(JSONObject.parseObject(testParam),TestEntity.class) ;
        System.out.println(testEntity.toString());
    }

TestEntity 为自己创建的实体类

方法二

JSONArray jsonArray= JSONArray.parseArray(jsonObject.get("body").toString());
        System.out.println(jsonArray +"::::"+ jsonArray.size());
        for(int i=0;i<jsonArray.size();i++){
            JSONObject object= (JSONObject) jsonArray.get(i);
            System.out.println(object.get("cabinet_id"));
        }

原文链接:https://blog.csdn.net/oowangfanoo/article/details/114025472

猜你喜欢

转载自blog.csdn.net/qq_44862029/article/details/126232375