list 转 JSONArray

list 转 JSONArray
后台方法:
1  JSONArray json  =   new  JSONArray();
2              String pareId  =  request.getParameter( " dicId " );
3              List list  =  zhidaoBO.getQuestionTDicByParentId(pareId); // 返回一个list
4              json  =  JSONArray.fromObject(list);
5               return   super .ajaxReturnJSON(request, response, json.toString());
页面接收到的结果:
[["402881c2219417340121945dd7d10008","瑜伽","zYoga"],
["402881c2219417340121945eeb730009","有氧健身操","zAerobicGym"]]
然后在回调函数里用js去操作
  1  $.post( " <c:url value='/user/zhidao/do.ao?method=getChildClass'/> " ,
 
2          { " dicId " :id},
 
3          function(json){
 
4            json = eval( ' ( ' + json + ' ) ' );
 
5            var obj  =  $( " #childSelect " );
 
6            obj.empty();
 
7             for (var i = 0 ;i < json.length;i ++ ){
 
8               // obj.append(<option value='" + json[i][0] + "'
                onclick='optionSelect(""" + json[i][0] + """)'>" + json[i][1] + "</option>");

  9              obj.append( " <option value=' "   +  json[i][ 0 +   " '> "   +  json[i][ 1 +   " </option> " );
10            }
11           });

你可能感兴趣的:(list 转 JSONArray)