如何将json字符串转换成对象
1个回答
展开全部
public Map jsonToObject(String jsonStr) throws Exception {
JSONObject jsonObj = new JSONObject(jsonStr);
Iterator<String> nameItr = jsonObj.keys();
String name;
Map<String, String> outMap = new HashMap<String, String>();
while (nameItr.hasNext()) {
name = nameItr.next();
outMap.put(name, jsonObj.getString(name));
}
return outMap;
}
JSONObject jsonObj = new JSONObject(jsonStr);
Iterator<String> nameItr = jsonObj.keys();
String name;
Map<String, String> outMap = new HashMap<String, String>();
while (nameItr.hasNext()) {
name = nameItr.next();
outMap.put(name, jsonObj.getString(name));
}
return outMap;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询