net.sf.json the string into map

background

Change a previous project, the project is only in this package, although I would like to use gson or fastjson, but does not want to introduce a new jar. So use this, hereby record, I feel bad thief with.

Implementation code

entity.getData () values: { AAA: BBB }

JSONObject jsonObject = JSONObject.fromObject(entity.getData());
Map<String, String> result = new HashMap<String, String>();
Iterator<String> iterator = jsonObject.keys();
String key = null;
String value = null;
while (iterator.hasNext()) {
    key = iterator.next();
    value = jsonObject.getString(key);
    result.put(key, value);
}

Guess you like

Origin www.cnblogs.com/jichi/p/11929617.html