如何获取ColdFusion方法以JSON格式的字符串返回数值? [英] How can I get ColdFusion methods to return numeric values as strings in JSON format?

查看:288
本文介绍了如何获取ColdFusion方法以JSON格式的字符串返回数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ColdFusion 8

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>

结果:

6762.0

应该会导致:

06762

获取JSON不能将我的值转换为数字?

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

我知道我可以使用WDDX,但这是不成问题。

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

推荐答案

确定,所以在CF8中没有 real 方法。解决方法是将字符添加到字符串的开头或结尾,然后在客户端代码中处理它。我使用美国邮政编码,所以它只是一个格式化每个ZIP为ZIP + 4(00000-0000)的问题。那里的小破折号使它成为一个字符串。

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.

这篇关于如何获取ColdFusion方法以JSON格式的字符串返回数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆