C#|c# HashtableTo Json 字符串 HashtableToWxJson

{"openid":"55","card_id":"55"}
var postData = https://www.it610.com/article/new Hashtable();
postData.Add("openid", "55");
postData.Add("card_id", "55");

#region 方法 HashtableToWxJson(Hashtable data) Hashtable表转JSON
///
/// Hashtable表转JSON
///
///
/// var postData = https://www.it610.com/article/new Hashtable(); postData.Add("openid", "55"); postData.Add("card_id", "55");
publicstring HashtableToWxJson(Hashtable data)
{
try
{
StringBuilder sb = new StringBuilder();
sb.Append("{");
foreach (object key in data.Keys)
{
object value = https://www.it610.com/article/data[key];
sb.Append("\"");
sb.Append(key);
sb.Append("\":\"");
if (!String.IsNullOrEmpty(value.ToString()) && value != DBNull.Value)
{
sb.Append(value).Replace("\\", "/");
}
else
{
sb.Append(" ");
}
sb.Append("\",");
}
sb = sb.Remove(sb.Length - 1, 1);
sb.Append("}");
return sb.ToString();
}
catch (Exception ex)
{
【C#|c# HashtableTo Json 字符串 HashtableToWxJson】return "";
}
}
#endregion

    推荐阅读