在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
#region Parse #region Dictionary Parse To String /// <summary> /// Dictionary Parse To String /// </summary> /// <param name="parameters">Dictionary</param> /// <returns>String</returns> static public string ParseToString(IDictionary<string, string> parameters) { IDictionary<string, string> sortedParams = new SortedDictionary<string, string>(parameters); IEnumerator<KeyValuePair<string, string>> dem = sortedParams.GetEnumerator(); StringBuilder query = new StringBuilder(""); while (dem.MoveNext()) { string key = dem.Current.Key; string value = dem.Current.Value; if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value)) { query.Append(key).Append("=").Append(value).Append("&"); } } string content = query.ToString().Substring(0, query.Length - 1); return content; } #endregion #region String Parse To Dictionary /// <summary> /// String Parse To Dictionary /// </summary> /// <param name="parameter">String</param> /// <returns>Dictionary</returns> static public Dictionary<string, string> ParseToDictionary(string parameter) { try { String[] dataArry = parameter.Split('&'); Dictionary<string, string> dataDic = new Dictionary<string, string>(); for (int i = 0; i <= dataArry.Length - 1; i++) { String dataParm = dataArry[i]; int dIndex = dataParm.IndexOf("="); if (dIndex != -1) { String key = dataParm.Substring(0, dIndex); String value = dataParm.Substring(dIndex + 1, dataParm.Length - dIndex - 1); dataDic.Add(key, value); } } return dataDic; } catch { return null; } } #endregion #endregion
|
请发表评论