• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

SerializeJSON for key value pairs?

Engaged ,
Dec 18, 2017 Dec 18, 2017

Copy link to clipboard

Copied

I've built a functional REST service that is successfully returning a query result:

<cffunction name="getAllOrders" access="remote" returntype="any" httpmethod="GET" returnFormat="json">

   <cfquery name="getAllOrders" datasource="test">

      select * from concreteOrder

   </cfquery>

   <cfset results = #serializeJSON(getAllOrders)#>

   <cfreturn results>

</cffunction>

I've been trying different formats but I'm not understanding the docs (my apologies, the holidays has made my brain fuzzy).

Does anyone know the correct format I should use in the serializeJSON() method to successfully bring back name:value pairs from the query results in my JSON object? All I've been able to do is bring back each row as a blob and then my Angular app can't do anything with that.... Ideally I'd like to bring back each row with something like "id": "1", "col2":"value", "col3":"value".... and so on

Views

645

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Dec 18, 2017 Dec 18, 2017

ugh, I just got it sorted out....

The docs are pretty in depth and here's what you need to do:

my cffunction code is fine, leaving it exactly as is all I did was add this line to my Application.cfc and problem solved:

<cfset this.serialization.serializeQueryAs='struct'/>

Saved, reloaded the REST service in the CF Admin and the new correct format works just fine.

I hope this helps someone else!

Votes

Translate

Translate
Engaged ,
Dec 18, 2017 Dec 18, 2017

Copy link to clipboard

Copied

LATEST

ugh, I just got it sorted out....

The docs are pretty in depth and here's what you need to do:

my cffunction code is fine, leaving it exactly as is all I did was add this line to my Application.cfc and problem solved:

<cfset this.serialization.serializeQueryAs='struct'/>

Saved, reloaded the REST service in the CF Admin and the new correct format works just fine.

I hope this helps someone else!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation