0

I cannot import my json data into a jQgrid. I get an empty grid. I hope someone has a solution.

The json data seems to be improperly formated.

It looks like this:

{
    "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" 
            ] 
        } 
    }
}

The problem is with the {"1" after "rows": and the "n" before each new {"id":

It should be "rows":[{"id"}

If I hand code the JSon it works.

The relevant php is:

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 is an object that has key/value configuration pairs in it.

The jSon output can be seen at:

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

I see a couple of possible approaches, but cannot figure either out.

  1. Get the jSon to format properly (i.e, what jQgrid expects)

  2. Configure jSonReader to handle my jSon

I will try and report back on any suggestions given to me.

Thanks.

Bill

Oleg
  • 220,925
  • 34
  • 403
  • 798

1 Answers1

0

I don't use PHP myself, but probably you should include the line

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

instead of the line

$rows = array();
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks, declaring the array as you suggested does not have any effect on the Json output. But I think the array may be the issue. – Bill Hogsett Mar 06 '11 at 03:59
  • @Bill Hogsett: Sorry, I wrote already that I didn't know PHP, but if `$responce['rows']` would be an array you would have correct `[...]` in the JSON after `"rows":`. Currently `$responce['rows']` is object with the properties "1", "2", ... so you have `"rows":{...}`. So your problem is **pure PHP** syntax problem: how you can create and fill array and then assign it to the `rows` property of the `$responce`. – Oleg Mar 06 '11 at 09:48