Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

returntype="JSON"

7 views
Skip to first unread message

Hector Torres

unread,
Sep 26, 2015, 1:48:01 AM9/26/15
to
So I have a component for which I want it to return the value in JSON format:

<!--- Get all grades TEST --->
<cffunction name="testQuery" access="remote" returntype="query" returnformat="JSON" output="false">
<cfset var qTestRet="">
<cfquery datasource="#APPLICATION.dsn#" name="qTestRet" >
SELECT [gradeId]
,[description]
FROM [dbo].[grades]
</cfquery>

<cfreturn qTestRet>
</cffunction>

It is converting the value to JSON but for some reason it is adding a COLUMNS and DATA values to my JSON and therefore I can't parse it correctly. Am I missing anything or is this the way ColdFusion creates a JSON out of a query?

This is the output:

json_query={"COLUMNS":["GRADEID","DESCRIPTION"],"DATA":[["1","Demuestra dominio de la habilidad/concepto, con ayuda directa"],["2","Demuestra dominio de la habilidad/concepto, con el minimo de auda"],["3","Demuestra dominio de la habilidad/concepto"],["4","Entiende el concepto/habilidad arriba del nivel de las expectativas de su grado"],["N/A","Aun no evaluado"]]}

Robert Zehnder

unread,
Sep 28, 2015, 9:53:03 AM9/28/15
to
I generally handle this by converting the query to an array before serializing and returning the value. Below is a method that will handle this for you.

You would need to modify your cfreturn as follows:

<cfreturn queryToArrayOfStructures(qTestRet) />

http://www.cflib.org/udf/QueryToArrayOfStructures
0 new messages