nalanrumeng 2020-05-02
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()); } }
spring-data-redis RedisTemplate 操作redis时发现存储在redis中的key不是设置的string值,前面还多出了许多类似\xac\xed\x00\x05t\x00;