Returning JSON response from Servlet to Javascript/JSP page

后端 未结 3 1954
小蘑菇
小蘑菇 2020-11-30 05:29

I think (actually I KNOW!) I\'m doing something wrong here I am trying to populate some values into HashMap and add each hasmap to a list which will be added to a JSON objec

3条回答
  •  隐瞒了意图╮
    2020-11-30 05:41

    Got it working! I should have been building a JSONArray of JSONObjects and then add the array to a final "Addresses" JSONObject. Observe the following:

    JSONObject json      = new JSONObject();
    JSONArray  addresses = new JSONArray();
    JSONObject address;
    try
    {
       int count = 15;
    
       for (int i=0 ; i

    This worked and returned valid and parse-able JSON. Hopefully this helps someone else in the future. Thanks for your help Marcel

提交回复
热议问题