Java string to JSON object

Java string to JSON object

 

String jsonStr = "{'message' : 'RDS-334 log work failed, Detail reason is Expect status:200, actual status:400,detail:{\"errorMessages\":[],\"errors\":{\"timeSpentSeconds\":\"32h exceeds daily limit of 24h\"}}', 'result' : 'false' }";
        
        //Use net.sf.json.JSONObject
        net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(jsonStr);
        System.out.println(jsonObject);
        System.out.println(jsonObject.get("message"));
        System.out.println(jsonObject.get("result"));
        
        //Use org.codehaus.jettison.json.JSONObject
        org.codehaus.jettison.json.JSONObject jsonObject2 = new org.codehaus.jettison.json.JSONObject(jsonStr);
        System.out.println(jsonObject2);
        System.out.println(jsonObject2.get("message"));
        System.out.println(jsonObject2.get("result"));
        
        //Use com.alibaba.fastjson.JSONObject
        com.alibaba.fastjson.JSONObject jsonObject3 = com.alibaba.fastjson.JSONObject.parseObject(jsonStr);
        System.out.println(jsonObject3);
        System.out.println(jsonObject3.get("message"));
        System.out.println(jsonObject3.get("result"));

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326615281&siteId=291194637