2010-12-18 37 views
1

我有一個從服務器返回的JSON數據的共同結構,它包含一些關於錯誤的其他信息等。我如何處理這些數據(檢查錯誤信息),然後只將需要的數據傳遞給網格。Jqgrid。如何處理服務器響應之前將傳遞到網格

這是JSON數據結構:

{ 
    "errorinfo": "foo", 
    "errormsg": "foo", 
    "errorCode": "foo" 
    "**jqgridData**": [ 
    { 
     "total": "xxx", 
     "page": "yyy", 
     "records": "zzz", 
     "rows" : [ 
     {"id" :"1", "cell" :["cell11", "cell12", "cell13"]}, 
     {"id" :"2", "cell":["cell21", "cell22", "cell23"]}, 
      ... 
     ] 
    } 
    ] 
} 

所以我棒來處理這個JSON數據,並傳遞給電網只有 「jqgridData

感謝您的幫助。

回答

0

首先,JSON數據有一個小錯誤。字符串

{ "errorinfo": "foo", "errormsg": "foo", "errorCode": "foo" "jqgridData": [ { 

必須改變,以

{ "errorinfo": "foo", "errormsg": "foo", "errorCode": "foo", "jqgridData": [ { 

(逗號"errorCode": "foo""jqgridData"之間必須插入)。我希望只有在問題文本中發佈數據時纔會出現問題。

您的主要問題。 jsonReader允許您幾乎讀取任何數據。你的數據應具有以下jsonReader被讀取:

jsonReader: { 
    root: "jqgridData.0.rows", 
    page: "jqgridData.0.page", 
    total: "jqgridData.0.total", 
    records: "jqgridData.0.records" 
} 

(其中「0」元素被作爲需要由於jqgridData索引附加陣列)。

+0

謝謝!我不知道我們可以在jsonReader中使用不同級別的數組。這非常有用! – NikeL 2010-12-19 09:32:28

相關問題