views:

45

answers:

3

ColdFusion 8

This is as simple pseudo-code as there can be:

<cffunction name="badJSON" access="remote" output="true" returntype="string" returnformat="JSON">
    <cfreturn "06762" />
</cffunction>

Results in:

6762.0

It should result in:

06762

Is there a way to get JSON to not convert my value to numeric?

I know I can use WDDX, but that is out of the question.

+1  A: 

I think this is fixed in CF9.0.1 with Cumulative Hotfix 1... which version are you using? If you really want "06762" you can try returntype="plain"

Henry
I think you're right that this JSON serialization issue is fixed in 9.0.1, but that's only helpful if he is using CF9. If using CF8, see Rick O's answer about JavaCast -- that should work on CF8.
Adam Tuttle
Yes, I hread it was fixed in CF9. The website I am working on is currently CF8.
Eric Belair
+2  A: 

Have you tried this?

return javaCast("string", "06762")

Rick O
+2  A: 

Ok, so there is no real way to do this in CF8. The workaround is to add a character to the beginning or end of the string, and then handle it in the client side code. I'm working with USA ZIP Codes, so it was simply a matter of formatting each ZIP as ZIP+4 (00000-0000). That little dash in there makes it a string.

Eric Belair