Common/JsonHelper.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Reflection;
namespace Common
{
public static class JsonHelper
{
public static string DataTableToJson(DataTable dt)
{
StringBuilder JsonString = new StringBuilder();
//Exception Handling
if (dt != null && dt.Rows.Count > 0)
{
JsonString.Append("{\"totalCount\":" + dt.Rows.Count.ToString() + ",");
JsonString.Append("\"JsonData\":[");
for (int i = 0; i < dt.Rows.Count; i++)
{
JsonString.Append("{");
for (int j = 0; j < dt.Columns.Count; j++)
{
if (j < dt.Columns.Count - 1)
{
JsonString.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":" + "\"" + dt.Rows[i][j].ToString() + "\",");
}
else if (j == dt.Columns.Count - 1)
{
JsonString.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":" + "\"" + dt.Rows[i][j].ToString() + "\"");
}
} /**/ /**/ /**/ /*end Of String*/
if (i == dt.Rows.Count - 1)
{
JsonString.Append("}");
}
else { JsonString.Append("},"); }
} JsonString.Append("]}"); return JsonString.ToString();
}
else { return null; }
}
public static string ListDataToJson<T>(bool isHasJsonData, IList<T> list, List<string> generateJson)
{
StringBuilder Json = new StringBuilder();
if (list != null && list.Count > 0)
{
if (isHasJsonData)
{
Json.Append("{\"totalCount\":" + list.Count.ToString() + ",");
Json.Append("\"JsonData\":[");
}
else
{
Json.Append("[");
}
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
