public string ToJson(DataSet ds)
{
StringBuilder sb = new StringBuilder();
sb.Append("{");
sb.Append("\"" + ds.DataSetName + "\": {");
for (int k = 0; k < ds.Tables.Count;k++ )
{
#region
sb.Append(" \"" + ds.Tables[k].TableName + "\": [");
for (int i = 0; i < ds.Tables[k].Rows.Count; i++)
{
if (i == ds.Tables[k].Rows.Count - 1)
{
#region
sb.Append("{");
for (int j = 0; j < ds.Tables[k].Columns.Count; j++)
{
if (j == ds.Tables[k].Columns.Count - 1)
{
sb.Append("\"" + ds.Tables[k].Columns[j].ColumnName + "\":");
sb.Append("\"" + ds.Tables[k].Rows[i][j] + "\"");
}
else
{
sb.Append("\"" + ds.Tables[k].Columns[j].ColumnName + "\":");
sb.Append("\"" + ds.Tables[k].Rows[i][j] + "\",");
}
}
sb.Append("}");
#endregion
}
else
{
#region
sb.Append("{");
for (int j = 0; j < ds.Tables[k].Columns.Count; j++)
{
if (j == ds.Tables[k].Columns.Count - 1)
{
sb.Append("\"" + ds.Tables[k].Columns[j].ColumnName + "\":");
sb.Append("\"" + ds.Tables[k].Rows[i][j] + "\"");
}
else
{
sb.Append("\"" + ds.Tables[k].Columns[j].ColumnName + "\":");
sb.Append("\"" + ds.Tables[k].Rows[i][j] + "\",");
}
}
sb.Append("},");
#endregion
}
}
if (k == ds.Tables.Count - 1)
{
sb.Append("]");
}
else {
sb.Append("],");
}
#endregion
}
sb.Append("}");
sb.Append("}");
return sb.ToString();
}
{
StringBuilder sb = new StringBuilder();
sb.Append("{");
sb.Append("\"" + ds.DataSetName + "\": {");
for (int k = 0; k < ds.Tables.Count;k++ )
{
#region
sb.Append(" \"" + ds.Tables[k].TableName + "\": [");
for (int i = 0; i < ds.Tables[k].Rows.Count; i++)
{
if (i == ds.Tables[k].Rows.Count - 1)
{
#region
sb.Append("{");
for (int j = 0; j < ds.Tables[k].Columns.Count; j++)
{
if (j == ds.Tables[k].Columns.Count - 1)
{
sb.Append("\"" + ds.Tables[k].Columns[j].ColumnName + "\":");
sb.Append("\"" + ds.Tables[k].Rows[i][j] + "\"");
}
else
{
sb.Append("\"" + ds.Tables[k].Columns[j].ColumnName + "\":");
sb.Append("\"" + ds.Tables[k].Rows[i][j] + "\",");
}
}
sb.Append("}");
#endregion
}
else
{
#region
sb.Append("{");
for (int j = 0; j < ds.Tables[k].Columns.Count; j++)
{
if (j == ds.Tables[k].Columns.Count - 1)
{
sb.Append("\"" + ds.Tables[k].Columns[j].ColumnName + "\":");
sb.Append("\"" + ds.Tables[k].Rows[i][j] + "\"");
}
else
{
sb.Append("\"" + ds.Tables[k].Columns[j].ColumnName + "\":");
sb.Append("\"" + ds.Tables[k].Rows[i][j] + "\",");
}
}
sb.Append("},");
#endregion
}
}
if (k == ds.Tables.Count - 1)
{
sb.Append("]");
}
else {
sb.Append("],");
}
#endregion
}
sb.Append("}");
sb.Append("}");
return sb.ToString();
}