Package com. Example. Fuxi. Utils;
The import com. Fasterxml. Jackson. Core. JsonProcessingException;
The import com. Fasterxml. Jackson. Databind. ObjectMapper;
The import com. Fasterxml. Jackson. Databind. SerializationFeature;
Import the Java. Text. SimpleDateFormat;
Public class jsonUntil {
Public static String getJson (Object obj) {
Return the getJson (obj, "YYYY - MM - DD HH: MM: SS");
}
Public static String getJson (Object obj, String DateFormat) {
ObjectMapper mapper=new ObjectMapper ();
Mapper. The configure (SerializationFeature WRITE_DATES_AS_TIMESTAMPS, false);
Final SimpleDateFormat SDF=new SimpleDateFormat (DateFormat);
Mapper. SetDateFormat (SDF);
Try {
Return mapper. WriteValueAsString (obj);
} the catch (JsonProcessingException e) {
e.printStackTrace();
}
return null;
}
}
Whether very concise
CodePudding user response:
With this package the JSONObject inside a see method with JSONArray class know is stem what of