Why ColdFusion adds the backslashes to my string concatenated?

Well, serializeJSON isn't enough create 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 asynchronous call AJAX with jQuery to the cfc that contains this code.

jQuery told me that the JSON was bad.

So I pulled out what Coldfusion has been sending 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 coldfusion adds a bar backslash before each quotation mark?

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

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

I've been at this for hours... what Miss me?

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

does not help...

You're not perform a JSStringFormat() on that anywhere, are you?  (maybe in the code not released).  JSStringFormat() assumes that the text passed to it is a literal string, and then he escaped values in quotes (as we see here)

In addition, on either said by the way, your JSON data is not valid, no?

Your loop will update the list of actions with a table, but it always takes into account there is another index of values, so it did precede the comma.  {[{You can even see in the final version of your data table ends with a '...},]}' you may need to make a conditional test to see if the loop is at its max index and if not, then add the comma.

Tags: ColdFusion

Similar Questions

  • Add the parameter to hardcoded string to decode function

    I have a query something like this:

    Select...
    ..............
    decode ((select bill_sequence_id
    of bom_structures_b one
    where a.assembly_item_id = POL. ITEM_ID
    and a.organization_id = FSP.INVENTORY_ORGANIZATION_ID
    and a.alternate_bom_designator is null
    and msi.bom_enabled_flag = 'Y'
    ), null, null, 'test_url | a.bill_sequence_id) "Destination".
    Of...
    where the...

    I want to add the value of the column that I looked at the end of "test_url.
    If I decode (..., null, null, 'test_url' | 222222222) it worked, but when I give bill_sequence_id or a.bill_sequence_id, he cries for invalid identifier.

    Please help.
    Thank you

    Hello

    Let me make sure I understand the problem.
    You want to return a value like

    'Today is = ' || x
    

    where x is a complex expression. But if x is NULL, you don't want to not return 'is now', you want to return null.
    What is the problem?

    Here's how you can do this without repeating x:

    NULLIF ( 'Today is = ' || x
           , 'Today is = '
           )
    

    A more general solution is to calculate the value in a subquery. In the Super request, you can see him as often you simply by using the alias that you gave in the subquery, like this:

    WITH    got_inner_select     AS
    (
         select a.dummy,
                (  select  b.dummy
                       from       dual       b
                where       a.dummy = b.dummy
                )  AS inner_select
         from   dual  a
    )
    SELECT     dummy
         DECODE ( inner_select
                , null     , null
                           , 'Today is = ' || inner_select
               )
    FROM     got_inner_select
    ;
    
  • How to add the field values custom calculation script

    Hello

    I have a calculation script:

    var bits = this.getField("DEXM").value;

    jib var = this.getField("acrofocus").value;

    var Misc = this.getField("acromisc").value;

    LVL var = this.getField("LVL").value;

    chk var = this.getField ("Check Box1.0") .isBoxChecked (0);

    {if(CHK==1)}

    Event.Value = (5 + jib + misc abi + (Math.floor (lvl/2))) ;}

    on the other

    {event.value = (jib + various + bits + (Math.floor (lvl/2))) ;}}

    I try to get the sum of the fields based on the value of a checkbox control. The if statement seems to work because the result does not change, but instead of adding up the results, it adds the numbers. Example: chk == 1, so add 5 + 0 + 0 + 2 + 1 and 8 display. But instead, it displays for event.value 521. All fields which events are digital with 0 decimal. What happens here? I expect that if they were formatted text fields, but they are not.

    Thank you all.

    You must explicitly convert the value of each field of a number. As an empty field values is a string type, the + operator gives you string concatenation instead of adding digital. You can review the first four lines of the script to:

    ABI = var + this.getField ("DEXM") .value;

    jib var = + this.getField ("acrofocus") .value;

    Misc = var + this.getField ("acromisc") .value;

    var = LVL + this.getField ("LVL") .value;

    and it should work properly.

  • Why not the type of the variable is a string?

    Hi, I need your help. \(´o `)/

    When I'm "DropDownList.items", the type of the variable dose not become the 'string. '
    Why?

    ------------------------------------------------------------------------------------------ ----------------------------------------
    var ddList = new Array();
    ddList = ["adobe", "DSP", "Japan"]; any value string table

    / * Create window * /.

    var = DLG

    "dialogue {text:"Interface of Script", limits: [200,200,460,350],"+}.

    "panel0:Panel {limits: [10,10,240,140], text:", properties: {borderStyle: "engraved", su1PanelCoordinates:true}, '+}.

    "ddownlist1:DropDownList {limits: [10,20,100,45]}, ' +.

    "button1:Button {limits: [10,55,100,80], text: 'Ok'}, ' +.

    "button2:Button {limits: [110,55,200,80], text: 'Cancel'}}} ';


    var win = new window (dlg, "click on the ok button!");

    for (var i = 0; i < ddList.length; i ++) {}

    Win.panel0.ddownlist1.Add ("Item", ddList [i]);   Add items to doropdownlist.

    }

    Win.panel0.ddownlist1.selection = 0;

    / * When the "ok" button is clicked... * /.
    Win.panel0.button1.onclick = function() {}

    var ddownlistItems = win.panel0.ddownlist1.items;

    for (var i = 0; i < ddownlistItems.length; i ++) {}

    / * If when 'isNaN' command was returned to 'true', while the type of the variable is "string", if it was referred to 'false', so no 'chain '.  *****/

    Alert ("ddownlistItems [" i + "] plus" + IsNaN (ddownlistItems [i]));

    }

    }

    Win.Show ();

    ------------------------------------------------------------------------------------------ ----------------------------------------

    I tried this script, "alert" has been returned "ddownlistItems [0] = false '.

    but the setting of the components dropdownlist used table of "channels".

    Why not the type of the variable is a string?

    Thank you.

    Because you do not test the chain only the index.

    try...

    Alert (ddownlistItems [i] + "=" + isNaN (ddownlistItems [i] .text));

  • flatten channel adds the length of the string

    Hi all

    I flatten a cluster chain help to flatten to string.vi. The cluster contains strings and arrays. The flattened string contains the length of the string that is appended to the string.

    So if I have a cluster with only 1 string and a value = "LabVIEW". the flattened string would be "0007LabVIEW". Flatten channel vi has a Boolean entry "add string or array of size? even if I set the Boolean value false, it always adds the length of the string. Is this a bug?

    I think that if you read the detailed help to flatten it to string function you will see this is not a bug.  That boolean applies only to top-level data, once put you something in a cluster or array, the Paris are open.

  • Add the string '&amp; lang = en '.

    I would like to add the string '& lang = en' to the path variable.

    < cfset newpath = path & "& lang = en" > ".

    < cfoutput > #newpath # < / cfoutput >

    The output is

    index.cfm < = en

    but not the desired output

    index.cfm & lang = en

    Help, please.

    There is a good chance that the exit IS 'index.cfm & lang = en', but your browser is to choose of does not display it like that.

    View the page source to confirm this.

    Short strings like the one that begins with an ampersand symbol (and) are often considered a character encoding on browsers.

    Alternatively, you can force the browser to display the string in the way desired with functions htmlCodeFormat() or htmlEditFormat().  Which, oddly enough, must be able to encode special characters such as the ampersand.

    I.E.

    #htmlEditFormat (newPath) #.

  • When I add the transparent button on the powerpoint slide, animation does not, why?

    I am a new user of Captivate 4.0. I gave a transparent button on a powerpoint slide that I inserted, to give navigation branching. The slide has animation too. At the point where I add the transparent button animation (fade images fade in) stops running after that I have published. Can someone help me with this.

    Thank you :-)

    Martine

    Hello

    Pure and simple. Buttons and objects Box click pause the slide until it clicked. If you want the slide to pause, change the button or box click so the break does not. Or change the "timing", so he made a break later.

    Out of curiosity, why a transparent button and not a click box? Basically, a click box is a transparent button.

    See you soon... Rick

    Useful and practical links

    Captivate wish form/Bug report form

    Certified Adobe Captivate training

    SorcerStone blog

    Captivate eBooks

  • Cannot add the debit card to Apple Watch

    I discovered lately that my Apple Watch does not have to pay for Apple.  I deleted the card from my iPhone 6 and added with no problems, but when I try to add the same card to my Apple Watch, it fails with the error pop up not added card - Contact your issuer of the card for more information. Add card later or try again.  I'm with Lloyd's bank, to the United Kingdom and do not understand why it seems to work on the iPhone but not the watch.

    Try to set up Apple pay on Apple Watch as described in the article configure Apple pay on your iPad, iPhone, or Apple Watch - Apple Support

  • How to add the custom search engine?

    Hello
    Firefox is a great browser especially for those who care about freedom and privacy. I would like to know why it is not possible to specify the custom search engine that you were able to do in the latest version of Firefox. I want to use the search engine google with https://search.disconnect.me/ which offers the possibility of anonymous research. I know that there is a plugin https://disconnect.me/search, but is not very comfortable with respect to the standard search bar. Thank you

    I read the solution proposed here https://support.mozilla.org/en-US/kb/use-search-bar-firefox-and-manage-search-engines#w_add-a-search-engine but in 36 of Firefox does not work

    TypeError message probably explains why you could not add the page of Mycroft search engine initially.

    When I search this exact error in Google, only that rolled up from July 2013:

    As long as the 'Integration of office of Unity 2.4.6' plugin is enabled I couldn't add to Firefox search engines.
    https://bugs.Launchpad.NET/Ubuntu/+source/unity-Firefox-extension/+bug/1202383

    Note: this option is not a Plugin, this is an Extension and available on the page Add-ons with other extensions.

  • What happened to add the button update?

    Previously, the help tab would show a feature update Add-ons,
    What happened to this service?

    Thanks for the tip and take the time
    to answer my question.

    Here is how I found this:

    go to 'tools '.

    Select "Add-ons" in the Tools menu

    Select 'Plugins' in the left menu

    Select 'check to see if your plugins are up to date.
    at the top of the list of Plugins.

    It was much easier when he was on the HELP page
    with a large icon, so I do not know why FireFox
    made the change.

  • Add the new entry name of folder of bookmarks does not

    (There's a reason I'm fool the previous thread on this subject, as well as my response to this: I couldn't find a way to add FireFox 10.0.2 to the tags of the thread.) If the thread tags may be edited/added, I wouldn't highlight problems with FireFox 10.0.2 by launching this new thread.)
    RE add new bookmarks folder, can not enter the name of the new folder:

    I am now having this problem with FireFox 10.0.2, 11/03/2012

    When I click on add a folder, a new folder appears in the tree view and the folder name field is highlighted for the entry. But when I start to type characters in the field, I can only type 1 or 2 characters at the most seized stops accept input. I then go to the bookmarks menu, locate the new folder, right-click it, click Properties and complete the registration of the name of the folder.

    At worst, the folder name field will cease to accept entry as soon as I type the first tank, in which case the name of the folder will remain as "new folder." I find the new folder in the bookmarks menu to change the name, as described above.

    It is very annoying because it adds a number of additional steps just to add a new folder in the bookmarks menu. Add the new folder through the "Show all bookmarks" and navigate through the folder hierarchy are an alternative workaround, but that records all the steps.

    Any ideas or solutions?

    Hi John99,
    It has worked well in Mode without failure. Thanks for the suggestion!

    I'm going offline a bit to understand what add-on, plugin, etc., could be causing it. In the meantime, I have marked your suggestion to use Mode safe as useful so that anyone else coming here could get the clue.

    I should probably drop another line in the thread for the guy who in (or has been) using FireFox 7...

    I'll post my results if I can understand it.

    UPDATE:

    I went after any add-on which had nothing to do with bookmarks.

    It was the first add-on I tried, SortPlaces 1.9.1 that automatically sorts bookmarks in various ways according to the parameters. When I disabled it, the problem disappeared.

    I re-enabled it and checked the options to see if I could understand why she was stop to add the new folder. In the 'Options' tab, there is a time limit for how long interval SortPlaces will wait before you sort a bookmark changed or added. It was set to 3 seconds.

    It is not long enough for old men by typing the new name of folder. I put it in 10 seconds. Then, I created a new folder of bookmarks and start typing a name long nonsense, while I looked at the clock. After that 10 seconds it stopped accepting the entrance, right on the mark. What this hidden for me earlier, it was that when he stops to accept input, you don't see the new folder to place in the position of sorting on the menu add a folder. You will see that if you expand the folder later. It's probably why I didn't connect the two.

    Anyway, problem solved. I'm leaving the delay to 10 seconds. If I ever need to be longer, I'll just increase it.

    Thanks again for the suggestion of Mode safe and enjoy the next season of mud.

    Alan Mintaka

  • I've installed a plugin to add the tab "duplicate" to the context menu for tabs. This was lost when I stupidly updated FF4 (my bad!). I don't remember how I added this feature, which is STANDARD with IE8, FF3.6! Tab Manager disobeys.

    I had installed a plugin to add the tab "duplicate" to right-click menu for tabs. This was lost when I stupidly updated FF4 (my bad). I don't remember how I added this feature, which is STANDARD with IE8, FF3.6! Tab Manager disobeys. WHY IS - IT NOT A STANDARD CONTAINED IN FF4?

    Could this be the add-on you think:

    https://addons.Mozilla.org/en-us/Firefox/addon/duplicate-this-tab/

  • Failed to add the network printer

    Hello

    We have a client that connects to our ERP system to print orders.  They connect through a VPN site-to-site and then access our system through an RDP connection to a server 2008R2 instance.  The printer is a HP LaserJet 4100tn

    When I first set up in the spring I was intending to use the easy print with the redirect to printer driver to print orders.  However exceptionally slowly printed orders and I was not able to determine why.  Instead I've implemented their LaserJet as a local printer on our desktop server remotely using a HP LaserJet 4100 Series PCL6 driver.  It worked perfectly, and they have been printing without problem until yesterday.

    Yesterday for some reason any printer stopped working.  On our Remote Desktop server, it appeared as grayed out with an exclamation mark above.  I did the following diagnosis:

    > They can print from their own local office it
    > They changed and turn it on again
    > I can ping the printer from our server OK
    > I can get on the web interface of the printer OK from our server
    > Restart our server remote desktop
    > Turn off the Windows Firewall on the Remote Desktop server

    I therefore decided to remove the printer and add it again.  I go through the configuration wizard Windows printer usual choosing to do a new TCP/IP port, but when I put the IP address of the printer in Windows says that it is not the printer on the network (photo attached).

    I tried to delete the printer port which has been associated with this printer and remove the driver but Windows still won't "see" the printer.

    I am able to configure this printer on other servers from RD (2003 and 2008) and I also tried setting up on an old XP box, I had to hang out without problem.  Curiously, it seems only that this server is the only one that I can not set up the new even if it can ping the printer OK.

    I found a troubleshooting printer HP hereWeb page but who was no help, and the software does not work on Windows Server versions.

    Don't know what to do next!

    This was solved by changing the IP address of the printer

    After changing the IP address, I was able to add the printer to the server OK.

    I wasn't able to find out why this is the case, but guess it is some incorrect IP or the information stored in the registry.

  • Add the table to report without timestamp

    Hello

    I try to use the Report Generation Toolkit for Office into my excel report.

    I have an excel template which I access via the generation of report vi in order to pass a double 2d array.

    The array is passed in the report, however, the vi seems to add a timestamp column.

    Is there a way to prevent the vi to add the timestamp.

    Thanks for any help you can give me.

    If anyone has the same problem, I just found that if you convert the 2d 2D array of strings table then the vi is more adds a timestamp.

  • MathScript adds the row of table

    Hello LabVIEWers,

    I recently encountered a problem using the MathScript that I don't understand.  When I create a simple table of dimension 1 and then access a single element in this array, MathScript and/or LabVIEW adds an extra line in this table.  This problem appears when I add the output for the MathScript structure array and create an indicator.  A VI sample that illustrates the problem I encounter is attached.  I have also run the same code MathScript in MatLab and the issue does not seem to occur.  Is there something that I am missing? Perhaps a logical reason and explantion for why LabVIEW for this?  I searched on the web, help and forums so far.  Any help is appreciated.

    My goal is to be able to access the items in a table without changing the dimensions of the table, or to manually remove the added row.

    Kind regards

    Doug

    Hello Doug77,

    In the line where you replace the 5th element of the array, if you say public (5) = 77, LabVIEW will not add the extra line. Almost everything in Mathscript if defined as a matrix. That's why you see size as 1.11. If you try to manipulate the public in the form of a 2D picture, saying test_array (1,5), mathscript guess it must be a 2D array.

    Let me know if it helps.

Maybe you are looking for