weixin_33674976 2017-05-27 20:10 采纳率: 0%
浏览 54

Ajax中的JSONArray循环

I tried to loop a JSONArray in my js file, and I have failed. Someone can help me please? this is my servlet code:

ArrayList<Campionato> campionati = DBManager.getInstance().getCampionatoDao().query();

    JSONArray jsonArray = new JSONArray(campionati);
    resp.getWriter().println(jsonArray);

and this is my Ajax code:

$.ajax({ 
    type: "GET",
    url: "MyServlet",
    dataType : "json",
    success: function(data){        

    alert("lenght "+ data.length); //this work but if i try data[0] it say me undefined

    //I don't know what should I put here for looping

    },
    error : function(data) {

    }

});

thanks all!

  • 写回答

4条回答 默认 最新

  • ℙℕℤℝ 2017-05-28 12:07
    关注

    Below code snippet iterate over json array using JQuery

        data = $.parseJSON(data); 
        $.each(data, function(i, item) { 
            alert(item);
         }) ;
    
    评论

报告相同问题?