Java系列之:获取Map格式数据

Java系列之:获取Map格式数据

  • 一、Map格式的数据转化为Json字符串
  • 二、遍历Map格式的数据

一、Map格式的数据转化为Json字符串

Map<String, String> headers = event.getHeaders();
String headerString = JSON.toString(headers);
LOG.info(headerString);

输出如下所示:

{
"hostname":"optics1",
"partition":"0",
"offset":"2415609410",
"topic":"optics_topic",
"project":"nio_business_prod",
"key":"{\"ver\":1,\"value_hash_code\":2051781190}",
"timestamp":"1645494385398"
}

二、遍历Map格式的数据

	Map<String, String> headers = event.getHeaders();
	for(Map.Entry<String, String> entry : headers.entrySet()){
    	LOG.info("<" + entry.getKey() + ", " + entry.getValue() + ">");
    }

你可能感兴趣的:(日常分享专栏,Java系列,获取Map格式数据)