public static JsonObject getJsonQuery ( URL url ) throws MalformedURLException { String query = url . getQuery ( ) ; JsonObject payload = new JsonObject ( ) ; JsonParser parser = new JsonParser ( ) ; if ( query == null ) { return null ; } for ( String kv : query . split ( "&" ) ) { String [ ] parts = kv . split ( "=" ) ; if ( parts . length != 2 ) { throw new MalformedURLException ( ) ; } String optName = parts [ 0 ] ; JsonElement optVal ; try { optVal = parser . parse ( URLDecoder . decode ( parts [ 1 ] , "UTF-8" ) ) ; } catch ( UnsupportedEncodingException e ) { throw new MalformedURLException ( ) ; } payload . add ( optName , optVal ) ; } return payload ; }
Parses a url - encoded query string and