【发布时间】:2011-10-09 17:06:30
【问题描述】:
我是 JAX-RS + RESTEasy 的新手
阻碍我的是服务返回不带双引号的 JSON 字符串。
@Path("/hello")
public class HelloService {
@GET
@Path("say")
@Produces(MediaType.APPLICATION_JSON)
public String say() {
return "Hello";
}
}
当我调用“/hello/say”时,它只会返回 Hello,但我期待的是 “Hello”
用 Google 搜索了几天。我有一段使用 JQuery 的 Javascript,它像这样调用服务:
$(function(){
$.ajax({
url : "services/hello/say",
context : $('#message'),
success : function(data){
$(this).html(data);
},
error : function(xhr, ajaxOptions, thrownError){
$(this).html(xhr.status + "<br>" + thrownError);
}
});
});
这就是结果
SyntaxError: Unable to parse JSON string
虽然状态是 200。 有没有办法解决这个问题,而不是手动将双引号添加到字符串中?
【问题讨论】: