背景
改一個以前的項目,項目里只有這個包,雖然我想用gson或者fastjson,然而並不想引入新的jar。於是使用這個,特此記錄,感覺賊不好用。
實現代碼
entity.getData()的值:{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);
}