Java URL Parameter Builder stringToMap(String input)

Here you can find the source of stringToMap(String input)

Description

string To Map

License

Open Source License

Declaration

public static Map<String, String> stringToMap(String input) 

Method Source Code


//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 {
    public static Map<String, String> stringToMap(String input) {
        Map<String, String> map = new HashMap<String, String>();

        String[] nameValuePairs = input.split("&");
        for (String nameValuePair : nameValuePairs) {
            String[] nameValue = nameValuePair.split("=");
            try {
                map.put(URLDecoder.decode(nameValue[0], "UTF-8"),
                        nameValue.length > 1 ? URLDecoder.decode(nameValue[1], "UTF-8") : "");
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException("This method requires UTF-8 encoding support", e);
            }//from  ww w. j a v  a 2  s  .  c om
        }
        return map;
    }
}

Related

  1. parseResponseParams(String body)
  2. sendGetRequest(String path, Map params, String enc)
  3. sendPostRequest(String path, Map params, String enc)
  4. serializeParameters(final Map parameters)
  5. serializeParameters(final Map params)
  6. stringToMap(String input)
  7. stringUncode(String param)