序列化与反序列化
1 KV结构且K不确定
Example:
public static void main(String[] args) { String response = "{\n" + " \"rule\":[\n" + " {\n" + " \"level\":\"info\",\n" + " \"on\": true,\n" + " \"ipList\":[],\n" + " \"router\":[\n" + " {\n" + " \"type\": \"default_type\",\n" + " \"id\":\"12312\"\n" + " }\n" + " ]\n" + " },\n" + " {\n" + " \"level\":\"error\",\n" + " \"on\": false,\n" + " \"ipList\":[\"127.0.0.1\"],\n" + " \"router\":[]\n" + " }\n" + " ]\n" + "}\n"; JSONObject dataJson = JSONObject.parseObject(response); Map<String, Object> map = dataJson.getInnerMap(); for (String key : map.keySet()) { List value = (List) map.get(key); System.out.println("key:" + key); for (Object object : value) { // 将字符串变为对象 Gson gson = new Gson(); LoggerSwitch loggerSwitch = gson.fromJson(object.toString(), LoggerSwitch.class); System.out.println("level:" + loggerSwitch.getLevel()); System.out.println("on:" + loggerSwitch.getOn()); System.out.println("ipList:" + loggerSwitch.getIpList()); System.out.println("router:" + loggerSwitch.getRouter()); } }
相关推荐
Lzs 2020-10-23
xclxcl 2020-08-03
zmzmmf 2020-08-03
葫芦小金刚 2020-07-22
ericdoug 2020-07-18
Erick 2020-06-17
aanndd 2020-06-16
Erick 2020-06-17
aanndd 2020-06-16
xuebingnan 2020-06-13
80337960 2020-06-10
Jerry 2020-06-01
mengdg000 2020-05-29
spring-data-redis RedisTemplate 操作redis时发现存储在redis中的key不是设置的string值,前面还多出了许多类似\xac\xed\x00\x05t\x00;
尹小鱼 2020-05-29
somebodyoneday 2020-05-15
visionzheng 2020-05-05
visionzheng 2020-05-04
igogo00 2020-05-03