I have version of the code that works fine in ColdFusion 10 but ColdFusion 9 I'm getting this error:
SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 1 column 13714 of the JSON data
Here is my cffunction where my data is converted to JSON:
<cffunction name="getBuildings" access="remote" output="true" returnformat="JSON">
<cfset fnResults = structNew()>
<cfquery name="getBldg" datasource="myData">
SELECT
LTRIM(RTRIM(number)) AS bldgNum,
LTRIM(RTRIM(name)) AS bldgName
FROM Bldg WITH (NOLOCK)
ORDER BY name
</cfquery>
<cfset fnResults.recordcount = getBldg.recordcount>
<cfif getBldg.recordcount EQ 0>
<cfset fnResults.message = "No Buildings found.">
<cfelse>
<cfloop query="getBldg">
<cfset fnRecBldg[currentRow] = StructNew()>
<cfset fnRecBldg[currentRow].bldgName = URLEncodedFormat(getBldg.name)>
<cfset fnRecBldg[currentRow].bldgNumber = getBldg.number>
</cfloop>
<cfset fnResults.data = fnRecBldg>
</cfif>
<cfset fnResults.status = "200">
<cfreturn fnResults>
</cffunction>
Here is my JQUERY:
function getBldg(){
var dist = $('.chBldg');
$.ajax({
type: 'POST',
url: 'Application.cfc?method=getBuildings',
data: {},
dataType: 'json'
}).done(function(obj){
var numRecs = obj.RECORDCOUNT;
if(obj.STATUS == 200){
if(numRecs == 0){
dist.find("option:gt(0)").remove();
}else{
dist.find("option:gt(0)").remove();
for(var i=0; i < numRecs; i++){
var jsRec = obj.DATA[i];
dist.append($("<option />").val(jsRec.BLDGNUMBER).text(decodeURIComponent(jsRec.BLDGNAME) +' ('+ jsRec.BLDGNUMBER +')'));
}
}
}else{
}
}).fail(function(jqXHR, textStatus, errorThrown){
alert(errorThrown);
});
}
}
Here is small example of rerurned data:
{"RECORDCOUNT":4,"STATUS":200,"DATA":[
{"BLDGNAME":"Fall%2DCasey","BLDGNUMBER":"0012"},
{"BLDGNAME":"Autmun","BLDGNUMBER":"0022"},
{"BLDGNAME":"Cedar","BLDGNUMBER":0201},
{"BLDGNAME":"Great%20Lake","BLDGNUMBER":1215}]}
This error must be related to ColdFusion version 9/10 and the way my JSON data is organized. I still didn't find the bug. If anyone see where my code id breaking please let me know.