我想发回一个Map>作为servlet的响应:
Map<UserAccount,ArrayList<CardSet>> sharedsets = DataDAO.getPublicSets();
String responseMessage = gson.toJson(sharedsets,Map.class);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.setStatus(HttpServletResponse.SC_ACCEPTED);
response.getWriter().write(responseMessage);
response.getWriter().flush();
...我在javascript中收到了这个消息:
$.get("/lod1/Scuttlebutt",{name:"onload",data: -1},function(jsondata){
console.log(jsondata);
});
..似乎列表已正确转换,但不是正确的键。我应该怎么做才能访问密钥的属性?我将如何用Javascript做到这一点?这是我在控制台中看到的输出:
Object
flashcardshark.bean.UserAccount@54
Array(16)
0
{Name: "a", setID: 1, description: "empty", status: "Shared"}
1
{Name: "d", setID: 2, description: "d", status: "Shared"}
2
{Name: "d", setID: 3, description: "d", status: "Shared"}
3
{Name: "d", setID: 4, description: "d", status: "Shared"}
4
{Name: "d", setID: 5, description: "ds", status: "Shared"}
5
{Name: "d", setID: 6, description: "dsadf", status: "Shared"}
6
{Name: "d", setID: 37, description: "d", status: "Shared"}
7
{Name: "a", setID: 59, description: "a", status: "Shared"}
8
{Name: "d", setID: 89, description: "d", status: "Shared"}
9
{Name: "d", setID: 90, description: "d", status: "Shared"}
10
{Name: "d", setID: 91, description: "dd", status: "Shared"}
11
{Name: "d", setID: 97, description: "d", status: "Shared"}
12
{Name: "d", setID: 100, description: "d", status: "Shared"}
13
{Name: "a", setID: 101, description: "a", status: "Shared"}
14
{Name: "d", setID: 102, description: "d", status: "Shared"}
15
{Name: "a", setID: 103, description: "a", status: "Shared"}
...因此,一切正常flashcardshark.bean.UserAccount@54