{
"msg_id": "36010000000000221589792383034",
"device_id": "3601000000000022",
"device_type":"ZDK",
"event_time": "1589792383",
"type": "DEVICE_REPORT",
"data": {
"subdev_id": "0101ec1bbdfffebb61c9",
"group_sid": "0101ec1bbdfffebb61c9",
"subdev_type": "0101ec1bbdfffebb61c9"
}
}
當給你這一串東西的時候,后端應該怎么接受呢,不多說了,直接貼代碼
@PostMapping("/test")
public Object test(@RequestBody Object object) {
JSONObject jsonObject = JSONObject.fromObject(object);
System.out.println(jsonObject.getJSONObject("data").getString("subdev_id"));
return null;
}
重點在於第一句代碼,轉換
但是要引入一個jar包
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
盡情玩轉Object跟json的轉換吧
