2011-03-05 59 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