public JsonElement get ( String label ) { int i = 0 ; try { for ( JsonElement e : this ) { if ( e . isPrimitive ( ) && e . asPrimitive ( ) . asString ( ) . equals ( label ) ) { return e ; } else if ( ( e . isObject ( ) || e . isArray ( ) ) && Integer . valueOf ( label ) . equals ( i ) ) { return e ; } i ++ ; } } catch ( NumberFormatException e ) { // fail gracefully return null ; } // the element was not found return null ; }
Convenient method providing a few alternate ways of extracting elements from a JsonArray .