ColdFusion10 restAPI returning malformed JSON because of special characters

78 views Asked by At

I have created a CFFunction that returns JSON from a query, but it is not returning special characters correctly. I have checked the record in the database and it is saving correctly in the database so I know the problem is with the API.

Below is the main of my cffunction:

<cffunction name="getNews" access="remote" httpmethod="GET" returntype="array" produces="application/json>

I have even tried adding charset=utf-8 at the end:

<cffunction name="getNews" access="remote" httpmethod="GET" returntype="array" produces="application/json; charset=utf-8">

but this still does not return the correct characters.

If there is anything else you need let me know, hopefully someone will have come across this issue before.

1

There are 1 answers

0
Anthony Doherty On

I managed to fix the problem:

  • Log into the CF Admin
  • Under "Server Settings" click "Java and JVM"
  • Under JVM Arguments add: -Dfile.encoding=UTF8
  • Restart the server and the page will display unicode.

I didn't have to change any other details in my API. Once I restarted the server the JSON came through correctly.