public string formatHtml(string jsonName, IList IL)
{
StringBuilder Json = new StringBuilder();
Json.Append("{" + jsonName + ":[");
if (IL.Count > 0)
{
for (int i = 0; i < IL.Count; i++)
{
T obj = Activator.CreateInstance();
Type type = obj.GetType();
PropertyInfo[] pis = type.GetProperties();
Json.Append("{");
for (int j = 0; j < pis.Length; j++)
{
string ILValue = "";
if (pis[j].GetValue(IL[i], null) != null)
{
ILValue = pis[j].GetValue(IL[i], null).ToString().Replace("'", "/"").Replace("/r", "").Replace("/n", "").Replace("//","");//关键就是这里,替换掉敏感字符就OK了
}
Json.Append("'" + pis[j].Name.ToString() + "':'" + ILValue + "'");
if (j < pis.Length - 1)
{
Json.Append(",");
}
}
Json.Append("}");
if (i < IL.Count - 1)
{
Json.Append(",");
}
}
}
Json.Append("]}");
return Json.ToString();
}