Coldfusion 10 返回格式=“JSON";添加字符 [英] Coldfusion 10 returnformat="JSON" adding characters

查看:20
本文介绍了Coldfusion 10 返回格式=“JSON";添加字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我正在将其从 CF8 转换为 CF10,而我的一些远程 CFC(其中返回的数据应该是 JSON)现在失败了,因为似乎有一个//"预先挂在返回的数据.例如这里是一个返回结构的输出:

I have an app that I'm working on converting from CF8 to CF10 and some of my remote CFCs where the data coming back should be JSON are now failing because there seems to be a "//" pre-pended to the returned data. For example here's an output of a returned structure:

//{"SUCCESS":true,"ERRORS":[],"DATA":{"COLUMNS":["AUTHRESULT","SPID","EMAIL","RID"],"DATA":[[true,361541,"user@domain.com",""]]}} 

在 CF8 服务器上通过相同的 CFC 运行相同的功能:

The same function run through the same CFC on the CF8 server gives:

{"ERRORS":[],"SUCCESS":true,"DATA":{"COLUMNS":["AUTHRESULT","SPID","EMAIL","RID"],"DATA":[[true,361541,"user@domain.com",""]]}} 

代理所有请求的 CFC 确实有 returnFormat="JSON" - 但在 proxyCFC 或从 proxyCFC 扩展的 CFC 中都没有调用 SerializeJSON().

The CFC that proxies all requests does have returnFormat="JSON" - but there is no SerializeJSON() being called in either the proxyCFC or the CFC that is extended from proxyCFC.

我不确定处理此问题的最佳方法是什么.修剪响应中的//"是可能的,但它似乎并不正确".我需要在 CF10 端解决它,因为这些功能不仅在我们的应用程序中使用,而且在一些远程应用程序中也使用(有些是通过 http://帖子,有些是通过 jQuery Ajax 调用).

I'm not sure what's the best way to handle this. Trimming off the '//' in the response would be possible but it doesn't seem "right". I need to address it on the CF10 end of things because these functions are in use not only in our app, but some remote apps as well (and some are through http:// posts and some are through jQuery Ajax calls).

推荐答案

这是ColdFusion 管理员,在设置下.为序列化的 JSON 加上前缀.出于安全考虑,它默认启用.保护 Web 服务,通过使用自定义前缀为序列化 JSON 字符串添加前缀,从而返回 JSON 数据免受跨站点脚本攻击..也许您已经在 ColdFusion 8 服务器上关闭了此功能.不过我不建议关闭它.

That is a server side setting in the ColdFusion admin, under settings. Prefix serialized JSON with. It is enabled by default for security. Protects web services, which return JSON data from cross-site scripting attacks by prefixing serialized JSON strings with a custom prefix.. Perhaps you had turned this off on your ColdFusion 8 server. I do not recommend turning it off though.

请参阅 Raymond Camden 的这篇文章 - 在 jQuery 和 jQueryUI 中处理带前缀的 JSON

See this post from Raymond Camden - Handling JSON with prefixes in jQuery and jQueryUI

注意:也可以通过在 Application.cfc 文件中设置 secureJSONsecureJSONPrefix 来为每个应用程序设置此设置.请参阅此处的文档 - 应用程序变量.

NOTE: this setting can also be set per-application by setting secureJSON and secureJSONPrefix in your Application.cfc file. See the documentation about that here - Application variables.

secureJSON - 一个布尔值,指定是否在 ColdFusion 函数以 JSON 格式返回以响应远程调用的值之前添加安全前缀.

默认值是管理员服务器设置 > 设置页面中前缀序列化 JSON 设置的值(默认为 false).您可以在 cffunction 标记中覆盖此值.

secureJSONPrefix - 如果 secureJSON 设置为 true,则放置在 ColdFusion 函数以 JSON 格式返回的值前面的安全前缀,以响应远程调用.

默认值是管理员服务器设置 > 设置页面中前缀序列化 JSON 设置的值(默认为//,JavaScript 注释字符).

这篇关于Coldfusion 10 返回格式=“JSON";添加字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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