如何从 ColdFusion 中的 CFC 返回小写 JSON?
我有一个 ColdFusion 组件,它将返回一些 JSON 数据:
component
{
remote function GetPeople() returnformat="json"
{
var people = entityLoad("Person");
return people;
}
}
不幸的是,返回的 JSON 的所有属性名称均为大写:
[
{
FIRSTNAME: "John",
LASTNAME: "Doe"
},
{
FIRSTNAME: "Jane",
LASTNAME: "Dover
}
]
有没有办法强制框架返回 JSON,以便属性名称全部为小写(也许是其他人编写的自定义 UDF/CFC)?
I have a ColdFusion component that will return some JSON data:
component
{
remote function GetPeople() returnformat="json"
{
var people = entityLoad("Person");
return people;
}
}
Unfortunately, the returned JSON has all the property names in upper case:
[
{
FIRSTNAME: "John",
LASTNAME: "Doe"
},
{
FIRSTNAME: "Jane",
LASTNAME: "Dover
}
]
Is there any way to force the framework to return JSON so that the property names are all lower-case (maybe a custom UDF/CFC that someone else has written)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,不幸的是,这就是 ColdFusion 的工作方式。设置某些变量时,您可以强制使用小写,就像结构一样:
将设置名称大写的变量。但是:
将强制使用小写(或驼峰式,具体取决于您传入的内容)。
但是对于您正在做的 ORM 工作,我认为您无法对其进行任何控制。如果我错了,有人纠正我。
Yeah, unfortunately, that is just the way ColdFusion works. When setting some variables you can force lowercase, like with structs:
Will set a the variable with uppercase names. But:
Will force the lowercase (or camelcase depending on what you pass in).
But with the ORM stuff you are doing, I don't think you are going to be able to have any control over it. Someone correct me if I am wrong.
如果你自己定义变量,你可以使用方括号表示法(如 Jason 的答案所示),但对于像 ORM 这样的内置东西,我认为你被困住了 - 除非你想创建自己的结构,并克隆 ORM 版本手动将每个键变成小写,但这并不是一个很好的解决方案。 :/
If you're defining the variables yourself, you can use bracket notation (as Jason's answer shows), but with built-in stuff like ORM I think you're stuck - unless you want to create your own struct, and clone the ORM version manually, lower-casing each of the keys, but that's not really a great solution. :/
这应该像你所描述的那样工作。
如果任何实体属性返回 null,则结构键将不存在。
要解决这个问题,请尝试这个
This should work as you described.
If any of your entity properties return null, the struct key wont exist.
To work around that try this