请问JQUERY怎么解析后台传来的JSON数据?
后台有一个有get set方法的user类,还有一个Vector colunms,里面装的是一条条的user对象,colunms[0]、colunms[1]等等都对应一个user对象,然后JSONArray json=JSONArray.fromObject(colunms);将这个Vector转换成json,json输出为String格式,以查看json的样式为
[{"id":{"children":"111","father":"部门2"}},{"id":{"children":"222","father":"部门2"}},{"id":{"children":"333","father":"部门2"}}]
这是后台形成的json串了,然后将没有toString过的json传回前台的回传函数中response.getWriter().println(json);
前台ajax方法:
$.ajax({
type: "GET",
url: "../search.do?method=searchIt",
dataType:"json",
data: "test",
success: function(colunms){
alert("success");
//问题就是在这个我该怎么处理传回来的colunms来取得其中各个字段的值呢?
}
});
------解决方案--------------------http://www.php100.com/html/webkaifa/ajax/2009/1206/3609.htmlhttp://fengyun1979101.blog.163.com/blog/static/9253190201022053812608/
------解决方案--------------------HTML code
var json = [{"id":{"children":"111","father":"部门3"}},{"id":{"children":"222","father":"部门2"}},{"id":{"children":"333","father":"部门2"}}];
$.each(json, function(i){
alert(json[i].id.children+" "+json[i].id.father);
});