1
votes

Following thie topic AngularJS - Special Characters in JSON and Coldfusion Request I have concluded that the problem didn't come from ANGULARJS or my JSON syntax. It's certainly a problem with Coldfusion.

For reminder, I'm trying to use a JSON string for doing an INSERT in a database with ColdFusion. I'm using a function defined in a component for doing that.

My function has the string as argument.

Here an example of the string used:

jsStruct={"LASTNAME":"Nämé","FIRSTN%a£öME":"TestFirstName","PHONENUMBER":48484488,"EMAIL":"[email protected]","COMPANY":"Test & Comp"}

My string is correct and the structure of the JSON is ok.

In my Coldfusion component "component.cfc":

    <cffunction name="myfunction" access="remote" returnformat="JSON" output="no">    
        <cfargument name="jsStruct" type="string" required="true">
        <cfset var cfStruct=DeserializeJSON(jsStruct)>

        ..................

    </cffunction>   

I obtain this error on the server when I use the string because in my string there is special characters. For instance "COMPANY":"Test & Comp":

JSON parsing failure: Unexpected end of JSON string


The error occurred in ../contacts.cfc: line 267

265 :       <cfargument name="jsStruct" type="string" required="true">
266 : 
267 :       <cfset var cfStruct=DeserializeJSON(jsStruct)>

Could you please help me to solve this problem and prevent (escape) special characters used by ColdFusion and Oracle as &, #, ', " and others?

1
The other topic solved not the problem on the server side. I conclude only that it's not a problem with AngularJs and with the JSON syntax. Now I would like solve the problem with Coldfusion.coeurdange57
Which version of ColdFusion are you using?Scott Jibben
jsStruct={"LASTNAME":"Nämé",... is not a JSON "string" but is declared as a CF struct. A string would be in single our double quotes like this: jsStruct='{"LASTNAME":"Nämé","FIRSTN%a£öME":"TestFirstName","PHONENUMBER":48484488,"EMAIL":"[email protected]","COMPANY":"Test & Comp"}'. The error you are getting is because you are using DeserializeJSON() on an object, not a JSON string/structure.Scott Jibben
Which version of ColdFusion are you using? Your example seems to work trycf.com/gist/604b27bea4ea3ce5cfab67cf49845bf8/…John Whish

1 Answers

0
votes

You say, in error,

My function has the string as argument. Here an example of the string used:

*jsStruct={"LASTNAME":"Nämé","FIRSTN%a£öME":"TestFirstName","PHONENUMBER":48484488,"EMAIL":"[email protected]","COMPANY":"Test & Comp"}*

You yourself call that a struct, which is correct. It is not a string.

Use something like:

jsonString='{"LASTNAME":"Nämé","FIRSTN%a£öME":"TestFirstName","PHONENUMBER":48484488,"EMAIL":"[email protected]","COMPANY":"Test & Comp"}';