jqGrid的一个错误 parsererror错误

jqGrid的一个错误 parsererror错误_第1张图片

在写jqgrid时出现如下错误

 

loadError: function (xhr, st, err) {
alert("Type: " + st + "; Response: " + xhr.status + " " + xhr.statusText); 
}, //处理服务器端的
错误原因:
1、在后台的ashx页面中没有给header指定编码
  public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "UTF-8";
2、返回的json对象的格式不正确

1.4(jquery)对json对象的字符串严格要求字符串(中的变量要用""引起来)

在我的生成json对象的语句 中

    /// <summary>
    /// jqgrid 格式数据
    /// </summary>
    /// <param name="dt">数据源datatable</param>
    /// <returns>string</returns>
    protected string GetGridJson(System.Data.DataTable dt)
    {
        StringBuilder jsonBuilder = new StringBuilder();

        jsonBuilder.Append("{/"page/":" + this.Pageindex + ",/"total/":" + this.Total
            + ",/"records/":" + this.Count + ",/"rows/"");
        jsonBuilder.Append(":[");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            jsonBuilder.Append("{/"id/":" + dt.Rows[i][0].ToString() + ",/"cell/":[");//错误的语句
            for (int j = 0; j < dt.Columns.Count; j++)
            {
                jsonBuilder.Append(GetJson<string>(dt.Rows[i][j].ToString()));
                jsonBuilder.Append(",");
            }
            jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
            jsonBuilder.Append("]},");
        }
        if (dt.Rows.Count > 0)
            jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
        jsonBuilder.Append("]");
        jsonBuilder.Append("}");
        return jsonBuilder.ToString();
    } 

字段id后面的值 没有用""引起来,所以报此错误信息

解决方法:
json错误语句更改为
 jsonBuilder.Append("{/"id/":/"" + dt.Rows[i][0].ToString() + "/",/"cell/":[");

你可能感兴趣的:(jqGrid的一个错误 parsererror错误)