我的代码如下:
@Path("/test")
public class Test {
@POST
@Path("/postSomething")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public RestMessageResponse postSomething(JSONObject inputJSONObject) {
..do something
}
}
当我向适当的网址发送 post 请求时,它不会到达代码。
最佳答案
你为什么要这样做?
只需在 HTTPRequest 中发送纯 JSON 并解析它即可。对我来说,这通常看起来像这样:
@RequestMapping(path= "/app/syncImages", method = RequestMethod.POST, produces = "application/json", consumes = "application/json")
public ResponseEntity<?> someMethod(@RequestBody String body){
JSONObject request = new JSONObject(body);
...
}
你试过你的代码吗?它在某些方面不起作用吗?
关于java - 我可以接受 JSONObject 作为 Rest API 中的参数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51284486/