自定义组装json对象

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