public Map<String,Object> getJson(JSONObject jsonObject, Map<String, Object> map) {
Set<String> keys = jsonObject.keySet();
for (String key : keys) {
Object object = jsonObject.get(key);
if (object instanceof JSONObject) {
map.put(key, object);
JSONObject jsonObject1 = (JSONObject) object;
getJson(jsonObject1, map);
} else if (object instanceof JSONArray) {
map.put(key, object);
JSONArray jsonArray = (JSONArray) object;
getJSONArrayTomap(jsonArray,map);
} else {
map.put(key, jsonObject.get(key));
}
}
return map;
}
public void getJSONArrayTomap(JSONArray jsonArray, Map<String, Object> map) {
for (Object object : jsonArray) {
if (object instanceof JSONObject) {
JSONObject jsonObject = (JSONObject) object;
getJson(jsonObject, map);
} else if (object instanceof JSONArray) {
JSONArray jsonArray1 = (JSONArray) object;
getJSONArrayTomap(jsonArray1, map);
}
}
}
将JSON字符串转换为Map格式
最新推荐文章于 2024-03-08 10:28:45 发布