Quantcast
Channel: Adobe Community: Message List - ColdFusion
Viewing all articles
Browse latest Browse all 21760

Why is ColdFusion adding backslashes to my Concatenated string?

$
0
0

Alright, serializeJSON isn't creating pretty enough JSON for me to use with jQuery.

 

So I decided to build it myself.

Here is my code:

 

 

<cffunction name="getActions" output="false" access="remote" returnformat="JSON">    <cfquery name="Actions">      SELECT * FROM Actions    </cfquery>    <cfset ActionsList = '{"success" : "true"}, {"Actions" : ['>    <cfloop query="Actions">      <cfset ActionsList = ActionsList & '{ "ID" : "'& ID & '", "Name" : "'& Name & '"},'>    </cfloop>    <cfset ActionsList = ActionsList & ']}'>    <cfreturn ActionsList>  </cffunction>

 

So basically I send an AJAX Asynchronous call with jQuery to the cfc that contains this code.

 

jQuery kept telling me the JSON was bad.

 

So I output what Coldfusion was sending back to the browser.

 

"{\"success\":\"true\"},{\"Actions\":[{\"ID\":\"1\",\"Name\":\"View Public\"},{\"ID\":\"2\",\"Name\":\"View Full\"},{\"ID\":\"3\",\"Name\":\"Create Page\"},
{\"ID\":\"4\",\"Name\":\"Create Part\"},{\"ID\":\"5\",\"Name\":\"Create Section\"},{\"ID\":\"6\",\"Name\":\"Create Question\"},{\"ID\":\"7\",\"Name\":\"Create Table\"},
{\"ID\":\"8\",\"Name\":\"Assign Pages to Location\"},{\"ID\":\"9\",\"Name\":\"Input Data\"},{\"ID\":\"10\",\"Name\":\"Edit Page\"},{\"ID\":\"11\",\"Name\":\"Edit Part\"},
{\"ID\":\"12\",\"Name\":\"Edit Section\"},{\"ID\":\"13\",\"Name\":\"Edit Question\"},{\"ID\":\"14\",\"Name\":\"Edit Table\"},
{\"ID\":\"15\",\"Name\":\"Assign Pages to Location Type\"},{\"ID\":\"16\",\"Name\":\"Add Location\"},{\"ID\":\"17\",\"Name\":\"Add Location Type\"},
{\"ID\":\"18\",\"Name\":\"Change Location\"},{\"ID\":\"19\",\"Name\":\"Assign Location Designee\"},{\"ID\":\"20\",\"Name\":\"Assign District Designee\"},
{\"ID\":\"21\",\"Name\":\"Update User Information\"},{\"ID\":\"22\",\"Name\":\"Add User Type\"},{\"ID\":\"23\",\"Name\":\"Manage Permissions\"},]}\""

 

Why is coldfusion adding a backslash before every double quote?

 

I built JSON the sam exact way in another function and it worked fine.

The only difference between that function and this one is this one has a loop.

 

I have been at this for hours... what am I missing?

 

and replace(ActionsList,"\","","ALL")

doesn't help...


Viewing all articles
Browse latest Browse all 21760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>