我在基于休息的 Web 服务中创建了以下休息方法
@GET
@Produces("application/json")
@Path("plain")
public String getPlain()
{
return "hello world";
}
@GET
@Produces("application/json")
@Path("wrapper")
public Response getWrapper()
{
return Response.ok(new Object(){ public String data = "hello world";}).build();
}
Run Code Online (Sandbox Code Playgroud)
当我调用普通服务时,它返回原始字符串hello world,而不是 JSON 格式的输出。但是,将字符串包装在对象中会返回 JSON {"data":"hello world"}
为什么它会表现出这样的行为?如何将纯字符串作为 JSON 发送?
sha*_*lic -2
尝试这个
@GET
@Produces("application/json")
@Path("plain")
public String getPlain()
{
String result= "hello world";
return result;
}
Run Code Online (Sandbox Code Playgroud)
JSON 需要一个键值对。
| 归档时间: |
|
| 查看次数: |
8914 次 |
| 最近记录: |