Groups | Search | Server Info | Login | Register


Groups > alt.comp.lang.coldfusion > #69

Re: returntype="JSON"

Newsgroups alt.comp.lang.coldfusion
Date 2015-09-28 06:53 -0700
References <1fc13002-71ff-40fc-93c2-40bf5a006387@googlegroups.com>
Message-ID <138e8f8a-cbfd-41b0-b2dc-436d3845279a@googlegroups.com> (permalink)
Subject Re: returntype="JSON"
From Robert Zehnder <robert@kisdigital.com>

Show all headers | View raw


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

On Saturday, September 26, 2015 at 1:48:01 AM UTC-4, Hector Torres wrote:
> 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"]]}

Back to alt.comp.lang.coldfusion | Previous | NextPrevious in thread | Find similar


Thread

returntype="JSON" Hector Torres <hectortorresa@gmail.com> - 2015-09-25 22:48 -0700
  Re: returntype="JSON" Robert Zehnder <robert@kisdigital.com> - 2015-09-28 06:53 -0700

csiph-web