服务器端我有这个Java:
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("application/json;charset=UTF-8");
resp.setHeader("Cache-Control", "no-cache");
PersistenceManager pm = PMF.get().getPersistenceManager();
Extent<Video> extent = pm.getExtent(Video.class, false);
ArrayList<Video> list = new ArrayList<Video>();
for (Video e : extent) {
list.add(e);
}
Gson gson = new Gson();
String json = gson.toJson(list);
System.out.println(json); // As expected: [{"id":34,"title":"a title","videoUrl":"an.mp4","imageUrl":"a.jpg" etc.
resp.getWriter().write(json);
extent.closeAll();
pm.close();
}
客户端我有这个使用 jQuery 的 JavaScript:
var getAllRequest = $.ajax({
url: "http://localhost:8888/getAll",
type: "GET",
dataType: "json"
});
getAllRequest.done(function(response) {
alert (response) // THIS IS AN OBJECT ARRAY, i.e., [object Object],[object Object] etc.
});
我的问题:响应真的是一个 json 对象,还是只是一个 json 对象数组。我正在使用 jq 网格,并且在给出响应时它不会填充网格。(将响应馈送到此处未显示的 jq 网格。)