回覆列表
  • 1 # 使用者8201481786170

    可以考慮把dataset或則datatable轉成json,如把 datatable的資料轉成json:

    ///

    /// Datatable轉換為Json

    ///

    /// Datatable物件

    ///

    public static string ToJson(DataTable dt)

    {

    StringBuilder jsonString = new StringBuilder();

    if (dt.Rows.Count == 0)

    {

    jsonString.Append("[{}]");

    return jsonString.ToString();

    }

    jsonString.Append("[");

    DataRowCollection drc = dt.Rows;

    for (int i = 0; i

    {

    jsonString.Append("{");

    for (int j = 0; j

    {

    string strKey = dt.Columns[j].ColumnName;

    string strValue = drc[i][j].ToString();

    Type type = dt.Columns[j].DataType;

    jsonString.Append("\"" + strKey + "\":");

    strValue = StringFormat(strValue, type);

    if (j

    {

    jsonString.Append(strValue + ",");

    }

    else

    {

    jsonString.Append(strValue);

    }

    }

    jsonString.Append("},");

    }

    jsonString.Remove(jsonString.Length - 1, 1);

    jsonString.Append("]");

    return jsonString.ToString();

    }

  • 中秋節和大豐收的關聯?
  • 玉有五德是哪五德?