我用 wink 写了一个简单的 RESTful Web 服务,其中有一个返回 JSONARRAY 的接口。我可以通过直接在浏览器中输入地址来获取json。然后,我开发了一个html页面,使用jquery的$.getJSON来调用web服务,但是在调试中我看到调用了服务方法,但是客户端页面无法获取json数据,怎么会呢?这是服务器上的方法:
@GET
@Produces(MediaType.APPLICATION_JSON)
public JSONArray getAllBook(){
JSONArray result = new JSONArray();
Collection<Book> books = BookStore.getInstance().getBooks();
for(Book book : books){
try{
result.put(BookStore.createJSONObject(book));
}catch(JSONException e){
e.printStackTrace();
}
}
return result;
}
这是js代码:
var url = "http://localhost:8080/WinkExBookLib/rest/book";
$.getJSON(url,function(data){
alter("aaa");
alter(data);
});