2014-11-06 3 views
1

아래 WebService에서 Json 응답을 받았습니다.Jqgrid가 데이터를 바인딩하지 않습니다.

Json이 데이터를 완벽하게 반환합니다. 데이터는 다음과 같습니다.

{ "d": "\"코드 \ ", \"mycode \ ", \"Name \ ": \"Myname \ ", \"PassWord 0, \ "DeptNo \": \ "\", \ "DeptName \": \ "\"}, \ "ID \": 3, \ "A \", \ "ClientLevel \ "코드 \": \ "mycode \", \ "이름 \": \ "ly1 \", \ "PassWord \": \ "mypassword \"............ 내 jqgrid를 바인딩하지 않습니다 ..

와 나는 내가 여전히 서버 측 D의 값이 속성은 문자열이기 때문에 (대신 객체의 문자열을 반환 WebMethod)에 예전의 코드를 사용하는 것이 생각있는 jqGrid 코드

jQuery("#list2").jqGrid({ 
       mtype: 'POST', 
       url: "myservice.asmx/GetQueryInfo",     

       serializeGridData: function (postData) { 
        return JSON.stringify({ 
         TableNames: TableName, 
         ColumnList: ColumnNames 
        }); 
       }, 

       ajaxGridOptions: { contentType: "application/json; charset=utf-8" }, 
       jsonReader: { 
         repeatitems: false, 
         root: 'd',       
         page: function (obj) { return 1; }, 
         total: function (obj) { return 1; }, 
         records: function (obj) { return obj.toString().length; } 
        }, 
       datatype: 'json', 
       colNames: ['ID', 'Code', 'Name', 'PassWord', 'ClientLevel', 'DeptNo', 'DeptName'], 
       colModel: [ 
        { name: "ID", width: 55 }, 
        { name: "Code", width: 90 }, 
        { name: "Name", width: 100 }, 
        { name: "PassWord", width: 80 }, 
        { name: "ClientLevel", width: 80 }, 
        { name: "DeptNo", width: 80 }, 
        { name: "DeptName", width: 150 } 
       ], 
       autoencode: true, 
       gridview: true, 
       rowNum: 10, 
       loadonce: true, 
       rowList: [10, 20, 30], 
       pager: '#pager2', 
       sortname: 'ID', 
       viewrecords: true, 
       sortorder: "ID", 
       caption: "JSON Example", 
       loadError: function (jqXHR, textStatus, errorThrown) { 
        alert('HTTP status code: ' + jqXHR.status + '\n' + 
          'textStatus: ' + textStatus + '\n' + 
          'errorThrown: ' + errorThrown); 
        alert('HTTP message body (jqXHR.responseText): ' + '\n' + jqXHR.responseText); 
       } 
      }); 
      jQuery("#list2").jqGrid('navGrid', '#pager2', { edit: false, add: false, del: false }); 

답변

1

을 다음 있습니다. 당신은 할 수 있습니다 01에 루트 사용 함수로서은 the answer과 같이 정의됩니다. 이 경우에는 귀하의 경우에도 작동합니다. 사용할 수 있도록

jsonReader: { 
    repeatitems: false, 
    root: function (obj) { 
     return typeof obj.d === "string" ? $.parseJSON(obj.d) : obj.d; 
    } 
} 
관련 문제