jQuery 中Ajax请求,前台获取不到返回json数据,大神们,帮帮忙咯

List<DbInfo> list = dbinfoService.queryDbinfo(text);//dbinfo是实体类
response.getWriter().print(JSONArray.fromObject(list));
$.ajax({
type: "post",
url:'querydbInfo.do',
data:{text:node.text},
dataType:"json",
success:function(data){
alert(data.id);//这里数据获取undefined
}
});
后台输出数据:[{"children":[],"createTime":{"date":30,"day":0,"hours":22,"minutes":56,"month":10,"nanos":0,"seconds":59,"time":1417359419000,"timezoneOffset":-480,"year":114},"creator":"testq","id":5,"info":"a","level":2,"name":"第一级4","parentId":1,"tableName":"testtable"}]
最新回答
折磨已成瘾゛

2024-05-12 16:55:50

可以用$.getJSON试试

用这个的话,把获取到的文本用eval包含
var data = eval(data);
alert(date.id);
々苏晓瑾丶訫冷控

2024-05-12 09:59:09

alert(data.id)是undefined,你可以先用chrome或Firefox,console.log(data);看看打印出来的data是什么,看看这个data是不是你从后台返回的数据!
眉眼藏欢

2024-05-12 14:40:08

alert(data[0].id)应该是这样的吧
这个是数组对象吧
沉默我的资本の

2024-05-12 10:12:29

你这是多维数组转化的JSON
是data.data.id吧

或者data.children.id