I'm trying to output a ColdFusion query to JSON so that it can be used with jQuery EasyUI (specifically a Datagrid).
From the example .json files that come with EasyUI this is the format they are looking for...
{"total":2
, "rows":[
{ "productid":"FI-SW-01"
, "productname":"Koi"
, "unitcost":10.00
, "status":"P"
, "listprice":36.50,"attr1":"Large"
, "itemid":"EST-1"
}
, { "productid":"K9-DL-01"
, "productname":"Dalmation"
, "unitcost":12.00
, "status":"P"
, "listprice":18.50
, "attr1":"Spotted Adult Female"
, "itemid":"EST-10"
}
]
}
However when I use SerializeJSON(emails)
on a ColdFusion query I get this:
{ "COLUMNS":["CUSTOMERID","CUSTOMERFIRSTNAME"]
, "DATA":[
[101,"Bhavin"],[102,"Frank"]
]
}
This does not seem to be recognized by EasyUI, so I guess the questions are (1) Should EasyUI be able to recognize and work with the output from ColdFusion as shown, or (2) Is there a way to make ColdFusion output the JSON in a format like the one included in the EasyUI example?
Update:
This is what it looks like if I use the serializeQueryByColumns
parameter:
{ "ROWCOUNT":83
, "COLUMNS":["CUSTOMERID","CUSTOMERFIRSTNAME"]
, "DATA":{
"CUSTOMERID":[101,102]
,"CUSTOMERFIRSTNAME":["Bhavin","Frank","]
}
}
Still not recognized by EasyUI though. In their documentation they show a php example that looks like this, so it's the output of this that I would be trying to replicate with ColdFusion I guess:
$rs = mysql_query('select * from users');
$result = array();
while($row = mysql_fetch_object($rs)){
array_push($result, $row);
}
echo json_encode($result);
Thanks!