title: JSON to Java gives errors
body: <p>I'm trying to parse this following JSON string to java. </p>
  
  <pre><code>{"Stdout":"Hello World\nThis is Sara","Stderr":"exit status 124"}
  </code></pre>
  
  <p>This string is dynamic and the content can be different as in,</p>
  
  <pre><code>{"Stdout":"Hello World\nThis is Sara","Stderr":""}
  </code></pre>
  
  <p>or</p>
  
  <pre><code>{"Stdout":"","Stderr":"exit status 124"}
  </code></pre>
  
  <p>I'm using the <a href="http://www.mkyong.com/java/json-simple-example-read-and-write-json/" rel="nofollow">following tutorial</a> and instead of the file I'm adding my String in it.</p>
  
  <p>So I created this code to simply print what <code>"Stdout"</code> and <code>"Stderr"</code> have to say:</p>
  
  <pre><code>public void parsed(String str) {
      JSONParser parser=new JSONParser();
      try {
          Object obj = parser.parse(str);
          JSONObject jsonObject = (JSONObject) obj;
          JSONArray out = (JSONArray) jsonObject.get("Stdout");
          Iterator&lt;String&gt; iterator = out.iterator();
          while (iterator.hasNext()) {
              System.out.println(iterator.next());
          }
          // loop array
          JSONArray err = (JSONArray) jsonObject.get("Stderr");
          Iterator&lt;String&gt; iterator2 = err.iterator();
          while (iterator2.hasNext()) {
              System.out.println(iterator2.next());
          }
  
      } catch (ParseException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>I'm getting the following result. And I have tried each and every possible solution that I found on Stack Overflow and other sites. <p></p>
  
  <p><code>java.lang.String cannot be cast to org.json.simple.JSONArray</code></p>