组装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;
        }

 

posted on 2019-12-19 15:39  红磨坊后的白桦树  阅读(219)  评论(0编辑  收藏  举报