Fork me on GitHub

【02-16】gson读取配置信息



	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static Map<String, Map<Integer, String>> getNodeAlarmInfoConfig(String filePath) {
		InputStream is = JsonTest.class.getResourceAsStream("/META-INF/test.json");
		String result;
		try {
			result = IOUtils.toString(is);
		} catch (IOException e) {
			e.printStackTrace();
			return new HashMap<>();
		}
		Map<String, Map<Integer, String>> config = new HashMap<>();
		HashMap map = new Gson().fromJson(result, HashMap.class);
		Set<Map.Entry> entrySet = map.entrySet();
		for (Map.Entry entry : entrySet) {
			String key = (String) entry.getKey();
			Map<Integer, String> innerMap = new HashMap<>();
			for (Object obj : (List) entry.getValue()) {
				Double innerKey = (Double) (((Map) obj).get("key"));
				innerMap.put(innerKey.intValue(), (String) ((Map) obj).get("value"));
			}
			config.put(key, innerMap);
		}
		return config;
	}
posted @ 2017-02-17 21:17  aloha_world  阅读(155)  评论(0编辑  收藏  举报