日期:2014-05-17  浏览次数:20572 次

$.getJSON(url, function(data) 获取不到值
获取到值转换成JSON
private static string GetCityList()      //返回值是一个json格式的字符串
    {

        DataTable dt = new DataTable();
        GXSW.GXSWBusiness g = new GXSW.GXSWBusiness();
        g.ExcuteSqlText = "select * from 系统分类 where 大类='试题类别'";
        g.ExcuteSQL();
        dt = g.GetDataTable();

        StringBuilder jsonBuilder = new StringBuilder();
        jsonBuilder.Append("{\"");
        jsonBuilder.Append("shitileibie");
        jsonBuilder.Append("\":[");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            jsonBuilder.Append("{");
            for (int j = 0; j < dt.Columns.Count; j++)
            {
                jsonBuilder.Append("\"");
                jsonBuilder.Append(dt.Columns[j].ColumnName);
                jsonBuilder.Append("\":\"");
                jsonBuilder.Append(dt.Rows[i][j].ToString());
                jsonBuilder.Append("\",");
            }
            jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
            jsonBuilder.Append("},");
        }
        jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
        jsonBuilder.Append("]");
        jsonBuilder.Append("}");
        return jsonBuilder.ToString();