String转Json函数:public static string SerializeObject(object value,Formatting formatting);
/// <summary>
/// 获取登录参数,使用的是json字符串
/// </summary>
private string GetLoginParameter()
{
List<LoginParameter> pList = new List<LoginParameter>();
LoginParameter loginParameter = new LoginParameter();
loginParameter.contactid = "1001";
loginParameter.password = "e10adc3949ba59abbe56e057f20f883e";
loginParameter.imei = "1";
pList.Add(loginParameter);
string ans = JsonConvert.SerializeObject(pList,Newtonsoft.Json.Formatting.Indented);
////去除开始的"["和结尾的"]"
//int ansStart = ans.IndexOf('{');
//int ansEnd = ans.IndexOf('}');
//ans = ans.Substring(ansStart,ansEnd - ansStart + 1);
////去除字符中间的空隙
//ans = ans.Replace("\n","");
//ans = ans.Replace("\r","");
//ans = ans.Replace("\t","");
return ans;
}
public class LoginParameter { public string contactid; public string password; public string imei; }
原文链接:https://www.f2er.com/json/290188.html