JSON Feed Quote Issue

Posted on 2012-09-10
Last Modified: 2012-09-11
I am trying to build an XML file from a JSON feed and it works great until my client started using "quotes" in a photo caption which the feed sends to my script.

I am accessing the JSON feed from Facebook for a photo album and can't ask my client to NOT use quotes in their photo descriptions. It would be the easy answer to this, but not practical.

With the feed I get, I use the below code to clean up the feed (per the ColdFusion site suggestion)  I added the last line of REReplace() to try and remove the quotes within the photo descriptions, but it isn't working.  The problem is that when the script finds a photo where the description (caption) has quotes in it, it simply stops my site from displaying the photos is gets from the feed because the XML file keeps the additional quotes in there and it breaks the script.

My cleanup code from the feed:
<cfset theData=REReplace(cfhttp.FileContent,  
<cfset theData=REReplace(theData, "\s*\)\s*$", "")>
<cfset theDate=REReplace(theData,"&quot;","")>

Open in new window

The resulting XML with a proper formatted and improper formatted result (notice the TITLE field results):
<pic image="" title="Rock the Arts Park Poster; Save the SkyVue Concert August 2012...Thank you New Castle, Indiana....You Rock! - Emma Petts Music" link="" link_title="" target="_self"/>
                        <pic image="" title="Emma Live At " Save the Vue" SkyVue Concert.  Sunday August 24, 2012 as she appeared with Benito for the benefit concert in New Castle, Indiana. (Eric Cox/ Knightstown Banner) - Emma Petts Music" link="" link_title="" target="_self"/>

Open in new window

They put quotes around SAVE THE VUE, which would aesthetically be correct in Facebook, but messes up my JSON feed to their website. It essentially only displays the photos up until the one that is messed up.

So how do I strip out their quotes?
Question by:day6
    LVL 51

    Expert Comment

    hmm, I don't see where you replace the quotes
    as I'm not a CF developer, I only can guess (assuming that REReplace does a global replace):

      <cfset theData=REReplace(theData, "\"", "")>
    LVL 19

    Accepted Solution

    I don't know how are you converting the JSON to your XML, but I presume that you'd need to do some data treatment.

    Have you tried just to add .replace(/"/g,"'") to the data extraction of your JSON?

    I mean, when you extract any string from the JSON feed just add it the replace and you'll obtain the same string with any " translated into a ', this should fix your problem.
    LVL 1

    Author Closing Comment

    While your suggestion isn't what ultimately worked, it inspired me to do a Replace() on the actual extracted field of data from the JSON feed and just do a Replace() on that field alone... which worked.  I did this

    <cfset nm=#struct2['name']#>
                       <cfset nm=Replace(nm,chr(34),"","all")>
                       <cfset nm=Replace(nm,chr(10),"","all")>
                       <cfset nm=Replace(nm,chr(13),"","all")>
    LVL 51

    Expert Comment

    hmm, then my CF syntax was more close than the JavaScript syntax ...

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    simple ajax form sumbit 9 38
    coldfusion, jQuery help 25 45
    GPS save in database 19 22
    Please explain a jQuery promise 5 23
    PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
    The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now