import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import java.util.*;
public class MdzwUtils {
public static Map<String, Object> parseJSON2Map(JSONObject json) {
Map<String, Object> map = new HashMap<String, Object>();
// 最外层解析
for (Object k : json.keySet()) {
Object v = json.get(k);
// 如果内层还是数组的话,继续解析
if (v instanceof JSONArray) {
List<Map<String, Object>> list = new ArrayList<>();
@SuppressWarnings("unchecked")
Iterator<JSONObject> it=((JSONArray) v).iterator();
while (it.hasNext()) {
JSONObject json2 = it.next();
list.add(parseJSON2Map(json2));
}
map.put(k.toString(), list);
} else {
map.put(k.toString(), v);
}
}
return map;
}
}
json 转换为 map 格式
最新推荐文章于 2025-04-18 16:21:26 发布