title: Granular indexing into json sub-array in Java, following conversion from string
body: <p>This journey starts with a message from a server, which becomes a string, initially it looks like this: </p>
  
  <pre><code>/713.105.135.149:54969: [{"row 0":[{},{},{},{},{},{},{},{}]},{"row 1":[{},{},{},{},{},{},{},{}]},{"row 2":[{},{},{},{},{},{},{},{}]},{"row 3":[{},{},{},{},{},{},{},{}]},{"row 4":[{},{},{},{},{},{},{},{}]},{"row 5":[{"column 0":"WhitePawn"},{},{},{},{},{},{},{}]},{"row 6":[{},{},{},{},{},{},{},{}]},{"row 7":[{},{},{},{},{},{},{},{}]}]
  </code></pre>
  
  <p>then I truncate all the stuff that's not valid JSON like so <code>message.substring(message.indexOf("["));</code></p>
  
  <p>Following that I cast it as a JSONarray, using this code <code>JSONArray jsonArray = new JSONArray(trimmed);</code></p>
  
  <p>Subsequently, I want to index into it, I can sort of do that like so <code>jsonArray.get(4);</code></p>
  
  <p>but this returns <code>{"row 4":[{"column 0":"WhitePawn"},{},{},{},{},{},{},{}]}</code>, whereas what I actually want is <code>WhitePawn</code>.</p>
  
  <p>The problem is that <code>jsonArray.get(4)</code> gave me back only a <code>JSONObject</code>, whereas what I think I need/want is another <code>JSONArray</code>, so I can once again index into it, something like <code>JSONArray subArray = jsonArray.get(0);</code>, the trouble is, that doesn't work. </p>
  
  <p>How can I make the result of <code>jsonArray.get(4)</code> return, or be cast to, something that I can again index into? </p>
  
  <p>The full code looks like this: </p>
  
  <pre><code>    private void parseMessageRedrawBoard(String message) throws Exception {
  
          Log.d("0000: ", message);
  
          String trimmed = message.substring(message.indexOf("["));
  
          Log.d("1111: ", trimmed);
  
          JSONArray jsonArray = new JSONArray(trimmed);
  
          //"column 0"
  
          Object subArray = jsonArray.get(4);
  
          Log.d("YES: ", subArray.toString());
      }
  </code></pre>