将json格式的字符串解析成Map对象

来源:互联网 发布:wpe网络封包编辑器 编辑:程序博客网 时间:2024/05/16 01:51
/**
* 将json格式的字符串解析成Map对象 <li>
* json格式:{"name":"admin","retries":"3fff","testname"
* :"ddd","testretries":"fffffffff"}
*/
private HashMap<String, String> toHashMap(JSONObject jsonObject) {
HashMap<String, String> data = new HashMap<String, String>();


Iterator it = jsonObject.keys();
// 遍历jsonObject数据,添加到Map对象
while (it.hasNext()) {
String key = String.valueOf(it.next());
String value = null;
try {
value = (String) jsonObject.get(key);
} catch (JSONException e) {
e.printStackTrace();
}
data.put(key, value);
}
return data;
}
0 0
原创粉丝点击