2011-03-05 56 views
0

我無法將json數據導入jQgrid。我得到一個空網格。我希望有人有一個解決方案。jQgrid Json格式幫助請求

json數據似乎是不正確的格式。

它看起來像這樣:

{ 
    "total": "3", 
    "page": "1", 
    "records": "71", 
    "rows": { 
     "1": { 
      "id": "1", 
      "cell": [ 
       1, 
       " Configuration Method", 
       "Using traditional Weather Display" 
      ] 
     }, 
     "2": { 
      "id": "2", 
      "cell": [ 
       2, 
       "CSSprint", 
       "weather-print-php.css" 
      ] 
     }, 
     "3": { 
      "id": "3", 
      "cell": [ 
       3, 
       "CSSscreen", 
       "weather-screen-black-narrow.css" 
      ] 
     } 
    } 
} 

的問題是與{"1" after "rows": and the "n" before each new {"id":

應該"rows":[{"id"}

如果我交出代碼JSON它的工作原理。

相關PHP是:

if($page > 1) 
     { 
      $i = $page*30; 
     } 
     else 
      $i = 1; 
$rows = array();  
$responce['total'] = "$total_pages"; 
$responce['page'] = "$page"; 
$responce['records'] = "$count"; 

foreach ($this->wdConfig as $key=>$value) 
    { 
     $responce['rows'][$i]['id'] = "$i"; 
     $responce['rows'][$i] ['cell'] = array($i,$key,$value); 
     $i++; 
    } 

$這-wdConfig的是,它具有鍵/值對配置的對象。

JSON的輸出可以看出:

http://billhogsett.com/wd/wd2/configToJson.php

我看到一對夫婦可能的方法,但找不出任何出。

  1. 獲取JSON格式正確(即什麼樣的jqGrid預計)

  2. 配置jSonReader來處理我的JSON

我會嘗試,並報告上給我什麼建議。

謝謝。

比爾

回答

0

我不使用PHP自己,但可能你應該包括行

$responce['rows'] = array(); 

,而不是線

$rows = array(); 
+0

謝謝,聲明數組作爲你的建議呢對Json輸出沒有任何影響。但我認爲陣列可能是問題。 – 2011-03-06 03:59:04

+0

@Bill Hogsett:對不起,我已經寫過,我不知道PHP,但是如果$ responce ['rows']'是一個數組,你將在JSON之後有正確的'[...]''行「:'。目前'$ responce ['rows']'是具有屬性「1」,「2」,...的對象,所以你有'「行」:{...}'。所以你的問題是**純PHP **語法問題:如何創建和填充數組,然後將其分配給'$ responce'的'rows'屬性。 – Oleg 2011-03-06 09:48:14