展开全部
map转成32313133353236313431303231363533e58685e5aeb931333363393633json格式
map map = new hashmap();
map.put(“users”, users);
map.put(“u”, u);
1.转成jsonarray类型
jsonarray json = jsonarray.fromobject(map);
system.out.println(json.tostring());//
[{“users”:[{“password”:“1234”,“username”:“cxl”},
{“password”:“1234”,“username”:“lhl”}],“u”:{“password”:“1234”,“username”:“lhl”}}]
response.getwriter().print(json.tostring);
js中取数据:alert(data[0].users[0].username);
2.转成jsonobject类型
jsonobject json = jsonobject.fromobject(map);
system.out.println(json);//
{“user”:[{“password”:“1234”,“username”:“cxl”},
{“password”:“1234”,“username”:“lhl”}],“u”:{“password”:“1234”,“username”:“lhl”}}
response.getwriter().print(json);
js中取数据:alert(data.user[0].username);