JSON Feed Quote Issue

Posted on 2012-09-10
Medium Priority
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="http://sphotos-b.xx.fbcdn.net/hphotos-ash3/s480x480/558468_340698272689957_769834684_n.jpg" 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="http://sphotos-a.xx.fbcdn.net/hphotos-ash4/s480x480/480827_340582309368220_853375246_n.jpg" 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
  • 2
LVL 51

Expert Comment

ID: 38386486
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

Bardobrave earned 1500 total points
ID: 38386506
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.

Author Closing Comment

ID: 38386787
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

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
Suggested Courses

864 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