【问题标题】:jQgrid Json Format Help RequestjQgrid Json 格式帮助请求
【发布时间】:2011-03-05 16:57:45
【问题描述】:

我无法将我的 json 数据导入 jQgrid。我得到一个空网格。我希望有人有解决方案。

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++;
    } 

$this-wdConfig 是一个包含键/值配置对的对象。

json 输出可见于:

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

我看到了几种可能的方法,但都想不通。

  1. 让 jSon 正确格式化(即 jQgrid 所期望的)

  2. 配置 jSonReader 来处理我的 jSon

我会尝试报告给我的任何建议。

谢谢。

比尔

【问题讨论】:

    标签: php json jqgrid format html-helper


    【解决方案1】:

    我自己不使用 PHP,但可能你应该包含该行

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

    而不是行

    $rows = array();
    

    【讨论】:

    • 谢谢,按照您的建议声明数组对 Json 输出没有任何影响。但我认为数组可能是问题所在。
    • @Bill Hogsett:抱歉,我已经写过我不了解 PHP,但如果 $responce['rows'] 是一个数组,那么您将在 "rows": 之后的 JSON 中拥有正确的 [...]。目前$responce['rows'] 是具有“1”、“2”等属性的对象,所以你有"rows":{...}。所以你的问题是 pure PHP 语法问题:如何创建和填充数组,然后将其分配给 $responcerows 属性。
    猜你喜欢
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    • 2010-12-05
    • 1970-01-01
    • 2012-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多