8

我有一个查询,我想将其转换为 JSON 对象。

在我的查询中,有一个字符串(例如"0000"or "0001")。不幸的是,在调用 之后SerializeJSON,String 是一个数字(0, 1, ...)。

使用 jQuery 调用函数时出现错误,因为 JSON 对象无效。引号失败:

{
   "COLUMNS": ["Test1","Test2","Test3"],
   "DATA": [ ["AA ",0000,"testestest"] ]
}

我已经尝试了很多东西。你能帮助我吗?

这是我的代码:

<cffunction name="getData" access="remote" returntype="any" returnformat="JSON">
    SQL....

    <cfset result = SerializeJSON(result)>

    <cfreturn result>
</cffunction>
4

3 回答 3

5

This a ColdFusion 9 bug which had been registered in the Adobe ColdFusion (Bug ID 83638). You can upgrade your ColdFusion to ColdFusion 9.0.1 to resolve this issue. You need to just install the hot fix.

Visit the following URL for installing the hot fix.

http://helpx.adobe.com/coldfusion/kb/cumulative-hotfix-1-chf1-coldfusion.html

This fix is already added in ColdFusion 10.

于 2013-01-09T11:49:05.483 回答
3

虽然不完全相同,但这里有一篇文章,我询问了关于将查询序列化为 json 以与 AngularJS 一起使用,这可能会有所帮助

于 2013-01-09T18:42:39.527 回答
3

此功能可能会有所帮助:http ://www.davidosomething.com/blog/fix-cf-serializejson-number-conversion

或者,使用这种方法: http ://www.ghidelli.com/2008/12/19/tricking-serializejson-to-treat-numbers-as-strings

您可以修改您的查询,以便它选择列并同时附加一些前导空格,例如

<cfquery>
  SELECT ' ' + Test2 AS yourColumn
于 2013-01-09T10:11:35.267 回答