Java URL Query Parse parseQueryStringEx(String queryString)

Here you can find the source of parseQueryStringEx(String queryString)

Description

parse Query String Ex

License

Apache License

Declaration

public static Multimap<String, String> parseQueryStringEx(String queryString)
            throws UnsupportedEncodingException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;

public class Main {
    public static Multimap<String, String> parseQueryStringEx(String queryString)
            throws UnsupportedEncodingException {
        Multimap<String, String> result = ArrayListMultimap.create();

        if (queryString == null) {
            return result;
        }/*from w w w  .  j  a v a2 s.  c  o  m*/

        for (String param : queryString.split("&")) {
            String pair[] = param.split("=");
            String key = URLDecoder.decode(pair[0], "UTF-8");
            String value = "";
            if (pair.length > 1) {
                value = URLDecoder.decode(pair[1], "UTF-8");
            }
            result.put(new String(key), new String(value));
        }

        return result;
    }
}

Related

  1. parseQueryString(String query, boolean ignoreEmpty)
  2. parseQueryString(String queryString)
  3. parseQueryString(String queryString)
  4. parseQuerystring(String queryString)
  5. parseQueryString(String queryString, Map params)
  6. parseURLQuery(String query)