json格式的字符串解析成Map对象
2016-09-14 本文已影响283人
梦沉薇露
private static HashMap<String, String> toHashMap(Object object)
{
HashMap<String, String> data = new HashMap<String, String>();
// 将json字符串转换成jsonObject
JSONObject jsonObject = JSONObject.fromObject(object);
Iterator it = jsonObject.keys();
// 遍历jsonObject数据,添加到Map对象
while (it.hasNext())
{
String key = String.valueOf(it.next());
String value = (String) jsonObject.get(key);
data.put(key, value);
}
return data;
}