public JSONObject parseObject ( String json ) throws JSONException { json = json . trim ( ) ; if ( json . startsWith ( "[" ) ) { JSONArray array = new JSONArray ( json ) ; JSONObject obj = new JSONObject ( ) ; obj . put ( "data" , array ) ; return obj ; } else { return new JSONObject ( json ) ; } }
Detects whether the inbound string is a JSONArray and if so wraps the array in an object with a single field called data