title: Android - Converting nested Maps to JSON String
body: <p>My app does HTTP requests using <a href="http://pastebin.com/aZzEe0vn" rel="nofollow">this <code>GsonRequest</code></a> implementation.
  Some of the requests parameters are not simple string keys and string values, but some values can be a map too.</p>
  
  <p>For instance:</p>
  
  <pre><code>{
      "Key1" : "value",
      "Key2" : {
          "Key2.1" : "value",
          "Key2.2" : "value",
          "Key2.2" : "value"
      },
      "Key3" : "value"
  }
  </code></pre>
  
  <p>The JSON parameters above can be built using <code>HashMap</code>s like this:</p>
  
  <pre><code>Map&lt;String, String&gt; subMap = new HashMap&lt;String, String&gt;();
  
  subMap.put("Key2.1", "value");
  subMap.put("Key2.2", "value");
  subMap.put("Key2.3", "value");
  
  Map&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  map.put("Key1", "value");
  map.put("Key2", subMap.toString());
  map.put("Key3", "value");
  </code></pre>
  
  <p>And then I call <code>GsonRequest</code> and pass <code>map</code>.</p>
  
  <p>However, when the request is made, the JSON sent is actually:</p>
  
  <pre><code>{
      "Key1" : "value",
      "Key2" : "{Key2.1 = value, Key2.2 = value, Key2.2 = value}", &lt;-- This is wrong
      "Key3" : "value"
  }
  </code></pre>
  
  <p>I tried to nest the maps using a <code>JSONObject</code>, with no success:</p>
  
  <pre><code>map.put("Key2.2", new JSONObject(subMap).toString());
  </code></pre>
  
  <p>will produce the  JSON:</p>
  
  <pre><code>...
  "Key2" : "{\"Key2.1\" : \"value\", \"Key2.2\" : \"value\", \"Key2.2\" : \"value\"}",
  ...
  </code></pre>
  
  <p>This one looks better, if I could escape the slashes it'd be right, but no.</p>
  
  <p>How can I nest the maps properly and get the JSON correctly?</p>