ColdFusion: QUERY to JSON

I have a request that I want to convert to a JSON object.

My query has a string (for example, "0000" or "0001" ). Unfortunately, after calling SerializeJSON string is a number ( 0 , 1 , ...).

I get an error when calling functions using jQuery because the JSON object is invalid. Quotation marks fail:

 { "COLUMNS": ["Test1","Test2","Test3"], "DATA": [ ["AA ",0000,"testestest"] ] } 

I have tried many times. Can you help me?

Here is my code:

 <cffunction name="getData" access="remote" returntype="any" returnformat="JSON"> SQL.... <cfset result = SerializeJSON(result)> <cfreturn result> </cffunction> 
+6
source share
3 answers

This is a ColdFusion 9 error registered in Adobe ColdFusion (Bug ID 83638). You can upgrade ColdFusion to ColdFusion 9.0.1 to solve this problem. You just need to install the fix.

Visit the following URL to install the hotfix.

http://helpx.adobe.com/coldfusion/kb/cumulative-hotfix-1-chf1-coldfusion.html

This hotfix is โ€‹โ€‹already added in ColdFusion 10.

+5
source

This feature may help: http://www.davidosomething.com/blog/fix-cf-serializejson-number-conversion

Alternatively, use this approach: http://www.ghidinelli.com/2008/12/19/tricking-serializejson-to-treat-numbers-as-strings

You can change your query so that it selects a column and at the same time adds some leading spaces, for example

 <cfquery> SELECT ' ' + Test2 AS yourColumn 
+3
source

Although itโ€™s not quite that there is a post here that I asked about serializing a json request for use with AngularJS, which may be useful

+3
source

All Articles