Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coldfusion can't display proper JSON object

I'm developing web app using coldfusion. When client send a request to the app, the app needs to send response back with JSON object. So I'm trying to display JSON object but I'm getting two slash "//" before my JSON object. That's why when I use isJSON function, it returns NO.

Here is the code I'm using in coldfusion:

<cfset usr_result= StructNew() />
<cfset usr_result = {'result'='success', 'type'='new'}>
<cfset json = SerializeJSON(usr_result)>

<cfoutput>
  #json#
  #isJson(json)#
</cfoutput>

Output is:

//{"result":"success","type":"new"} NO

I'm expecting

{"result":"success","type":"new"} YES

Any suggestions?

Thank you!

like image 995
aeh Avatar asked Nov 30 '25 05:11

aeh


2 Answers

Check the CF administrator. There is a setting labeled: Prefix serialized JSON with. Turn that setting off.

like image 165
Scott Stroz Avatar answered Dec 01 '25 19:12

Scott Stroz


In addition to turning off the JSON prefix at the server level, you can turn off the prefix at the application level. In your application.cfc, you can add this.secureJSON = false to turn off the prefixing of the JSON string.

like image 32
Twillen Avatar answered Dec 01 '25 19:12

Twillen