C#中拼接JSON字符串
(2011-11-07 09:39:32)
标签:
杂谈 |
分类: 网页 |
public string GetActiveFiles(string selectsection)
{
DataTable dt = DALWebService.GetFiles(selectsection);
DataTable FinalTable = new DataTable();
FinalTable.Columns.Add("ID", typeof(int));
FinalTable.Columns.Add("DownloadURL", typeof(string));
FinalTable.Columns.Add("Shortname", typeof(string));
FinalTable.Columns.Add("Filename", typeof(string));
foreach (DataRow item in dt.Rows)
{
DataRow FileRow = FinalTable.NewRow();
FileRow["ID"] = Convert.ToInt32(item[0]);
FileRow["DownloadURL"] =
"http://www.antunnel.com.cn:9099/Downloads/" +
DALAccounts.GetClientNameID(Convert.ToInt32(item[2])) + "/" +
Convert.ToInt32(item[1]).ToString() + "/Storage/" +
item[3].ToString();
FileRow["Filename"] = item[3].ToString();
FileRow["Shortname"] = item[4].ToString();
FinalTable.Rows.Add(FileRow);
}
char[] specialChars = new char[] { ',' };
string JSONstring = "[";
int index = 0;
foreach (DataRow dr in FinalTable.Rows)
{
JSONstring += "{";
foreach (DataColumn dc in FinalTable.Columns)
{
JSONstring += "\"" + dc.ColumnName + "\":\"" + dr[dc].ToString() +
"\",";
}
JSONstring = JSONstring.TrimEnd(specialChars);

加载中…