{ "kpi1": 0, "kpi2": 0, "kpi3": 0, "kpi4": 0, "kpi5": -3, "kpi6": -3, "kpi7": 20971520000, "kpi8": 0, "kpi9": 0, "kpi10": 0, "kpi11": 0, "kpi12": 0, "kpi13": 0, "mo_id": "307434295fd494ab3b303da202c94517", "object_id": "Eth-Trunk4.3004", "gather_time": 1683650700000 } 用Java转成map
时间: 2023-06-19 10:08:43 浏览: 406
可以使用以下代码将JSON字符串转换为Java Map对象:
```
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
String jsonStr = "{ \"kpi1\": 0, \"kpi2\": 0, \"kpi3\": 0, \"kpi4\": 0, \"kpi5\": -3, \"kpi6\": -3, \"kpi7\": 20971520000, \"kpi8\": 0, \"kpi9\": 0, \"kpi10\": 0, \"kpi11\": 0, \"kpi12\": 0, \"kpi13\": 0, \"mo_id\": \"307434295fd494ab3b303da202c94517\", \"object_id\": \"Eth-Trunk4.3004\", \"gather_time\": 1683650700000 }";
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> map = objectMapper.readValue(jsonStr, new TypeReference<Map<String, Object>>(){});
// 输出map
System.out.println(map);
```
输出结果如下:
```
{kpi1=0, kpi2=0, kpi3=0, kpi4=0, kpi5=-3, kpi6=-3, kpi7=20971520000, kpi8=0, kpi9=0, kpi10=0, kpi11=0, kpi12=0, kpi13=0, mo_id=307434295fd494ab3b303da202c94517, object_id=Eth-Trunk4.3004, gather_time=1683650700000}
```
阅读全文