[英]java playframework read json from request body
I want to read a json from a request body. 我想从请求体中读取一个json。
my in body I have: 我的身体我有:
DefaultRequestBody(None,None,None,None,None,Some(MultipartFormData(Map(json -> List({"a":"s","b":"sd"})),List(),List(),List())))
Now I want to access the List ... what would be the best way in this case? 现在我想访问List ...在这种情况下最好的方法是什么?
I have tried this: 我试过这个:
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);
}
}
but json is always null 但是json总是空的
thanks 谢谢
this workes for me 这适合我
Http.RequestBody body = request().body();
JsonNode json = body.asJson();
System.out.println(json);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.