参数名ASCII码从小到大排序(字典序)

时间:2024-11-25 11:07:31
 /// <summary>
/// Hashtable字典排序
/// </summary>
/// <param name="parameters"></param>
/// <param name="encode"></param>
/// <returns></returns>
public static string formatParameters(Hashtable parameters, Boolean encode)
{
StringBuilder sb = new StringBuilder();
ArrayList akeys = new ArrayList(parameters.Keys);
akeys.Sort();
foreach (string k in akeys)
{
string v = (string)parameters[k];//防止参数不是字符串
sb.Append(k.ToLower() + "=" + v + "&");
}
//去掉最后一个&
if (sb.Length > 0)
{
sb.Remove(sb.Length - 1, 1);
}
return sb.ToString();
}