Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Unicode Characters from Twitter JSON API feed using ColdFusion

I'm trying to use the Twitter API to pull down statuses from the Lists API using ColdFusion and am parsing everything I need just fine using the JSON format and a JSON component.

The problem I've come across is trying to convert the Unicode characters so they display correctly on screen.

here is the sample data that comes from the JSON feed

F\u00e0bregas

Is there some regex I could use to convert this?

Currently I have it writing out the raw data from the JSON feed

#node.user.name#

Which is fine, but it contains the \u00e0 which I need to convert so it displays as Fàbregas with the correct accent over the 'a'.

like image 759
Simon Hume Avatar asked Dec 07 '25 13:12

Simon Hume


1 Answers

First up I think this is more of an character encoding issue than a regex issue.

How are you getting the Twitter data? If it's using <cfhttp> you could try setting the charset attribute to UTF-8. This will ensure that the data from Twitter arrives in UTF-8.

Then you should explicitly set the character encoding on the page you are trying to output the data on (the FORM and URL encoding while you are at it). For example:

<!--- URL and FORM encoding to UTF-8 --->
<cfset setEncoding("URL", "UTF-8") />
<cfset setEncoding("FORM", "UTF-8") />

<cfcontent type="text/html; charset=UTF-8" />

<cfoutput>#node.user.name#</cfoutput>

You'll find some more info here. Hope that helps!

like image 169
Ciaran Archer Avatar answered Dec 09 '25 15:12

Ciaran Archer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!