参数名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();
        }

  

posted @ 2016-11-07 14:44  方金  阅读(28712)  评论(0编辑  收藏  举报