Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well I found a way to get an arbitrarily nested List/Map object back through a conversion process. Probably awfully inefficient as it relies on multiple JSONExceptions, but does what I need:</p> <pre><code>private static Map&lt;String, Object&gt; jsonObjectToMap(JSONObject object) { @SuppressWarnings("unchecked") Iterator&lt;String&gt; keys = object.keys(); String key; Map&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;(); while (keys.hasNext()) { key = keys.next(); try { map.put(key, jsonObjectToMap(object.getJSONObject(key))); } catch (JSONException e) { try { map.put(key, jsonArrayToList(object.getJSONArray(key))); } catch (JSONException e1) { try { map.put(key, object.getString(key)); } catch (JSONException e2) { try { map.put(key, object.getInt(key)); } catch (JSONException e3) { try { map.put(key, object.getLong(key)); } catch (JSONException e4) { try { map.put(key, object.getBoolean(key)); } catch (JSONException e5) { try { map.put(key, object.getDouble(key)); } catch (JSONException e6) { try { map.put(key, object.get(key)); } catch (JSONException e7) { // TODO Auto-generated catch block e7.printStackTrace(); } } } } } } } } } return map; } private static List&lt;Object&gt; jsonArrayToList(JSONArray array) { List&lt;Object&gt; arrayList = new ArrayList&lt;Object&gt;(); for (int i = 0; i &lt; array.length(); i++) { try { arrayList.add(jsonObjectToMap(array.getJSONObject(i))); } catch (JSONException e) { try { arrayList.add(jsonArrayToList(array.getJSONArray(i))); } catch (JSONException e1) { try { arrayList.add(array.getString(i)); } catch (JSONException e2) { try { arrayList.add(array.getInt(i)); } catch (JSONException e3) { try { arrayList.add(array.getLong(i)); } catch (JSONException e4) { try { arrayList.add(array.getBoolean(i)); } catch (JSONException e5) { try { arrayList.add(array.getDouble(i)); } catch (JSONException e6) { try { arrayList.add(array.get(i)); } catch (JSONException e7) { // TODO Auto-generated catch block e7.printStackTrace(); } } } } } } } } } return arrayList; } </code></pre> <p>Would be great if support for this could be built in to json.org as an alternative way of returning the data, rather than having to do an expensive conversion.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload