private static JSONArray getArray ( JsonObject object , String key ) throws IOException { // Get the existing one if ( object . containsKey ( key ) ) { Object existing = object . get ( key ) ; if ( ! ( existing instanceof JSONArray ) ) { throw new IOException ( "Invalid field structure, '" + key + "' expected to be an array, but incompatible " + "data type already present." ) ; } return ( JSONArray ) existing ; // Or add a new one } else { JSONArray newObject = new JSONArray ( ) ; object . put ( key , newObject ) ; return newObject ; } }
Get a child JSON Array from an incoming JSON object . If the child does not exist it will be created .