{ "locations": [{ "_id": null, "coords": {}, "name": null, "placeType": null }] } 

How to add a value to the placeType parameter using a HashMap looking at this json?

  • 3
    and not better here to arrange the data class? - Mikhail Rebrov
  • Like this? I did not understand something ... The problem here is that locations have an array. If there were no [] these signs. That I would add without problems. And since the request does not pass, since I do not make out the request so - Andro

1 answer 1

Try to transfer Json to HashMap , and then without any problems add values ​​to the map.

 public Map<String, Object> toMap(JSONObject object) throws JSONException { Map<String, Object> map = new HashMap<String, Object>(); Iterator<String> keysItr = object.keys(); while(keysItr.hasNext()) { String key = keysItr.next(); Object value = object.get(key); if(value instanceof JSONObject) { value = toMap((JSONObject) value); } map.put(key, value); } return map; }