在方法中返回json对象 [英] Returning json object in a method
本文介绍了在方法中返回json对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我想用我的java方法返回这个
Hi
I want to return this in my java method
return Json(new
{
Success = true,
Redirect = url,
//I want to return stock object here,
});
@POST
@Path("/posting")
@Consumes({ MediaType.APPLICATION_JSON })
public User posting(User stock) {
//other code here
boolean Success;
String Redirect;
//Below code is incorrect
return Json(new
{
Success = true,
Redirect = url,
//I want to return stock object here,
});
}
如何使用JsonObject返回此方法?
How can i return this method using JsonObject?
推荐答案
@POST
@Path("/posting")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
public javax.ws.rs.core.Response posting(User stock) {
//other code here
boolean success;
String redirect;
ResponseDTO dto = new ResponseDTO();//Simple class to hold return values (value object)
dto.setSuccess(success);
dto.setRedirect(redirect);
return javax.ws.rs.core.Response.ok(dto).build();
}
这篇关于在方法中返回json对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文