Java Utililty Methods Json Parse

List of utility methods to do Json Parse

  1. HOME
  2. Java
  3. J
  4. Json Parse

Description

The list of methods to do Json Parse are organized into topic(s).

Method

Map getMapFromGson(String json)
get Map From Gson
Type type = new TypeToken<Map<String, String>>() {
}.getType();
return G.fromJson(json, type);
T json2Obj(String json, Class clazz)
json Obj
ObjectMapper objectMapper = new ObjectMapper();
try {
 objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
 return objectMapper.readValue(json, clazz);
} catch (Exception e) {
 e.printStackTrace();
 return null;
String jsonString(String s)
json String
if (s == null)
 return null;
StringBuffer b = new StringBuffer();
b.append("\"");
CharacterIterator it = new StringCharacterIterator(s);
for (char c = it.first(); c != CharacterIterator.DONE; c = it.next()) {
 if (c == '"')
 b.append("\\\"");
...
Date parse(JSONObject jsonobj)

parse.

DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date d = format.parse(jsonobj.getInt("year") + "-" + jsonobj.getInt("month") + "-" + jsonobj.getInt("day"));
return d;
T parse(String json, Class tClass)
parse
try {
 return mapper.get().readValue(json, tClass);
} catch (Exception e) {
 throw new RuntimeException(e);
Date parseDateFromJsonArray(final JsonArray array)
Parses a JsonArray to a Date .
Preconditions.checkNotNull(array);
final GregorianCalendar calendar = new GregorianCalendar(array.get(0).getAsInt(),
 array.get(1).getAsInt() - 1, array.get(2).getAsInt());
final SimpleDateFormat format = new SimpleDateFormat("dd MMMM yyyy");
return format.parse(format.format(calendar.getTime()));
Map parseJson(String jsonText, String[] params)
parse Json
JSONObject jo = new JSONObject(jsonText);
Map<String, Object> result = new HashMap<String, Object>();
for (int i = 0; i < params.length; i++) {
 result.put(params[i], jo.get(params[i]));
return result;
java.util.Date parseJSONDate(String _dateStr)
parse JSON Date
return parseDate(_dateStr, "yyyy-MM-dd'T'HH:mm:ss");


AltStyle によって変換されたページ (->オリジナル) /