我想从请求正文中读取 json。
我的 body 有:
DefaultRequestBody(None,None,None,None,None,Some(MultipartFormData(Map(json -> List({"a":"s","b":"sd"})),List(),List(),List())))
现在我想访问列表...在这种情况下最好的方法是什么?
我已经尝试过这个:
JsonNode json = request().body().asJson();
if(json == null) {
System.out.println("NULL");
return badRequest("Expecting Json data");
} else {
String name = json.findPath("name").toString();
if(name == null) {
return badRequest("Missing parameter [name]");
} else {
return ok("Hello " + name);
}
}
但 json 始终为 null
谢谢
最佳答案
这对我有用
Http.RequestBody body = request().body();
JsonNode json = body.asJson();
System.out.println(json);
关于java playframework从请求体读取json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43345471/