Reputation: 617
I’ve been pulling my hair out on this issue. On my local computer the value “00” (double zeroes) is wrapped with within a quote but on the server it doesn’t wrap the double quote around it.
Ajax Call:
var loadFriends = $.ajax({
type: "GET",
url: "/webFolder/friends/list",
dataType: "json",
data: {vID: 15},
cache: false,
success: function(returnData){
var d = cfQueryNormalize(returnData);
// console.log(d);
// return;
if (!jQuery.isEmptyObject(d)) {
do something...
}else{
do something...
}
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(textStatus);
console.log(errorThrown);
}
});
// script from Raymond Camden @ http://www.raymondcamden.com/2012/5/11/Using-CFC-data-with-Handlebars
function cfQueryNormalize(d) {
var result = [];
for(var i=0, len=d.DATA.length; i<len;i++) {
var item = {};
for(var k=0,innerlen=d.COLUMNS.length; k<innerlen; k++ ) {
item[d.COLUMNS[k].toLowerCase()] = d.DATA[i][k];
}
result.push(item);
}
return result;
}
The column is question is the fid in the second object with an id of 60.
Local computer return this:
[Object { id="59", fid="5D", vid="15", more...}, Object { id="60", fid="00", vid="15", Object { id="61", fid="00", vid="07", more...}, more...}]
Server returns this:
[Object { id="59", fid="2K", vid="15", more...}, Object { id="60", fid=00, vid="15", Object { id="61", fid="04", vid="15", more...}, more...}]
Error message in Firebug:
My local computer is running windows 7, ACF CF 9,0,1,274733, and IIS7. The server is running windows 2008 R2, ACF 9,0,2,282541, and IIS7. The only notable difference I see is the ColdFusion version. Any suggestion is greatly appreciated, thank you.
Upvotes: 2
Views: 121
Reputation: 29870
ColdFusion has been rife with JSON bugs. It doesn't surprise me something was fixed in 9.0.2. That said, this looks like your bug here: "SerializeJSON casts multiple zero value as number instead of string". But this bug was not fixed until CF10.0.10, according to the bugbase. So seems odd it's behaving differently on two different minor releases of CF9?!
I endeavoured to make use of serializeJson()
on ColdFusion 9 (see my blog label "JSON" for exactly how much strife it gave me). In the end, we decided CF's JSON support was not fit for purpose in CF9, and have stopped using it for anything other than the most superficial uses.
My suggestion is to do the same: simply surrender.
I had some luck with Google's GSON library, if that's an option. If absolutely will not serialise ColdFusion query objects though.
Upvotes: 2