Parsing query strings on Android

前端 未结 25 1361
时光说笑
时光说笑 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

    Guava's Multimap is better suited for this. Here is a short clean version:

    Multimap getUrlParameters(String url) {
            try {
                Multimap ret = ArrayListMultimap.create();
                for (NameValuePair param : URLEncodedUtils.parse(new URI(url), "UTF-8")) {
                    ret.put(param.getName(), param.getValue());
                }
                return ret;
            } catch (URISyntaxException e) {
                throw new RuntimeException(e);
            }
        }
    

提交回复
热议问题