标签:tle result 序列 sele turn 序列化 serial body ati
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());
}
}