组装json对象
public string strTree(DataTable dt, string type, string state) { string strjosn = ""; foreach (DataRow dr in dt.Rows) { if (string.IsNullOrEmpty(strjosn)) { strjosn = "{\"id\":\"" + dr[1] + "\",\"text\":\"" + dr[0] + "\",\"state\":\"" + state + "\",\"attributes\":{\"type\":\"" + type + "\"}}"; } else { strjosn += "," + "{\"id\":\"" + dr[1] + "\",\"text\":\"" + dr[0] + "\",\"state\":\"" + state + "\",\"attributes\":{\"type\":\"" + type + "\"}}"; } } strjosn = "[" + strjosn + "]"; return strjosn; }
原文地址:https://www.cnblogs.com/macT/p/12068150.html
时间: 2024-10-07 13:22:24