参数名ASCII码从小到大排序(字典序)
/// <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(); }
本文来自博客园,作者:方金,转载请注明原文链接:https://www.cnblogs.com/Gold-fangjin/p/6038869.html