问题
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:
Have you tried this?
return javaCast("string", "06762")
回答2:
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.
回答3:
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"
来源:https://stackoverflow.com/questions/3640003/how-can-i-get-coldfusion-methods-to-return-numeric-values-as-strings-in-json-for