Parsing query strings on Android

前端 未结 25 1395
时光说笑
时光说笑 2020-11-22 17:41

Java EE has ServletRequest.getParameterValues().

On non-EE platforms, URL.getQuery() simply returns a string.

What\'s the normal way to properly parse the qu

25条回答
  •  生来不讨喜
    2020-11-22 17:42

    If you have jetty (server or client) libs on your classpath you can use the jetty util classes (see javadoc), e.g.:

    import org.eclipse.jetty.util.*;
    URL url = new URL("www.example.com/index.php?foo=bar&bla=blub");
    MultiMap params = new MultiMap();
    UrlEncoded.decodeTo(url.getQuery(), params, "UTF-8");
    
    assert params.getString("foo").equals("bar");
    assert params.getString("bla").equals("blub");
    

提交回复
热议问题