Here you can find the source of encodeParameters(Map
Parameter | Description |
---|---|
parameters | a parameter |
public static String encodeParameters(Map<String, List<String>> parameters)
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.List; import java.util.Map; public class Main { /**//from w w w. j av a2 s. co m * Returns a properly encoded string of parameters. * * @param parameters * @return */ public static String encodeParameters(Map<String, List<String>> parameters) { if (parameters == null) { return ""; } StringBuilder b = new StringBuilder(); boolean first = true; for (String key : parameters.keySet()) { if (!first) { b.append("&"); } first = false; List<String> values = parameters.get(key); try { if (values.size() == 1) { String value = values.get(0); b.append(URLEncoder.encode(key, "UTF-8")).append("=").append(URLEncoder.encode(value, "UTF-8")); } else { for (String value : values) { b.append(URLEncoder.encode(key + "[]", "UTF-8")).append("=") .append(URLEncoder.encode(value, "UTF-8")); } } } catch (UnsupportedEncodingException ex) { throw new Error(ex); } } return b.toString(); } }