我有这个方法:
@GET
@Path("/myservice")
@Produces(MediaType.APPLICATION_JSON)
public Response mysercice() {
boolean userExists = false;
CacheControl cacheControl = new CacheControl();
cacheControl.setNoCache(true);
cacheControl.setNoStore(true);
JSONObject jsonObject = new JSONObject();
jsonObject.put("userExists", userExists);
return Response.ok(jsonObject, MediaType.APPLICATION_JSON).cacheControl(cacheControl).build();
}
在浏览器中访问方法的url时,得到{},表示对象为空。所以,我尝试使用:
return Response.ok(jsonObject.toString(), MediaType.APPLICATION_JSON).cacheControl(cacheControl).build();
所以,我进入浏览器 {"userExists" : false} 但我不明白为什么在简单地返回 JSONObject 时,我们在浏览器中得到一个空对象。