title: I can't read a JSON with getJson
body: <p>I know that my question has been answered many times but I still cannot figure out how to make one work for me.
  I am trying 2 days now to fix my problem by reading the forum but I have probably something wrong in the basics which I cannot find and in which I will need your help.</p>
  
  <p>I have a servlet that creates a JSON(at least I think so) and here is the code</p>
  
  <pre><code>        JSONObject json = new JSONObject();
      for(int i=0; i&lt;20; i++){
          JSONObject jsonItem = new JSONObject();
          jsonItem.put("position", positions[i]);
          json.accumulate("group", jsonItem);
      }
  
      String output = json.toString();
  
      response.setContentType("application/json");    
      PrintWriter out = response.getWriter();  
      out.print(output);
      out.flush();
  </code></pre>
  
  <p>If I run the servlet I am getting the following:</p>
  
  <pre><code>{
    "group": [
      {
        "position": 235
      },
      {
        "position": 61
      },
      {
        "position": 248
      },
      {
        "position": 206
      },
      {
        "position": 26
      },
      {
        "position": 329
      },
      {
        "position": 176
      },
      {
        "position": 180
      },
      {
        "position": 218
      },
      {
        "position": 83
      },
      {
        "position": 177
      },
      {
        "position": 142
      },
      {
        "position": 17
      },
      {
        "position": 249
      },
      {
        "position": 310
      },
      {
        "position": 369
      },
      {
        "position": 251
      },
      {
        "position": 256
      },
      {
        "position": 337
      },
      {
        "position": 63
      }
    ]
  }
  </code></pre>
  
  <hr>
  
  <p>My jQuery is as following:</p>
  
  <pre><code>$(document).ready(function(){
    $("#clickMe2").click(function(){
        alert("something2");
      $.getJSON("/RandomNumGen",function(result){
          alert("something3");
        $.each(result, function(i, field){
          $("#myTarget").append(field + " ");
        });
      });
    });
  });
  </code></pre>
  
  <p>Maybe it's not the right way to read it but it never goes to the second alert "something3". So I think it never reads the JSON.
  I tried many ways to read it but it seems that the problem was that never reads the JSON.</p>
  
  <p>I am running the servlet on a tomcat 7.0.22 and I have the <code>@WebServlet("/RandomNumGen")</code> which I think that means that I don't need a web xml but wasn't running so I decided to create a web.xml as well.
  The weird thing is that when I tried once to return something with a MIME "text/html" and getting it with normal get <code>$.get</code> it does get it and it prints <code>[Object object]</code> on the browser.</p>
  
  <p>Apparently I haven't used JSON before and I might miss the basics as I run really fast through the tutorials. </p>