Here you can find the source of queryToParams(String query)
name1=value1&name2=value2
and return it as Map
Parameter | Description |
---|---|
query | Query string |
Parameter | Description |
---|---|
UnsupportedEncodingException | an exception |
public static Map<String, String> queryToParams(String query) throws UnsupportedEncodingException
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.HashMap; import java.util.Map; public class Main { /**//from www .j av a 2 s . c o m * Parse given query string of the form <code>name1=value1&name2=value2</code> and return it as {@link Map} * * @param query Query string * @return Parsed results * @throws UnsupportedEncodingException */ public static Map<String, String> queryToParams(String query) throws UnsupportedEncodingException { Map<String, String> query_pairs = new HashMap<String, String>(); String[] pairs = query.split("&"); for (String pair : pairs) { int idx = pair.indexOf("="); query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8")); } return query_pairs; } }