Coldfusion 11 和 Coldfusion 2016 之间的编码问题
Encoding problem between Coldfusion 11 and Coldfusion 2016
我目前使用 ColdFusion 11 作为本地服务器进行开发。
我有一个用 ColdFusion 序列化的 JSON 字符串。在字符串中,我必须在对象 "Payment_form" 中插入一个代码“99”。响应中所需的 Api 告诉我 Payment_form 对象是一个字符串。
了解使用 JSON 字符串和数字表示的 ColdFusion 序列化问题,请查看 Whosebug 并通过放置 "chr(2)".
找到解决方案
问题已解决....但仅在 ColdFusion 11 中。当我将代码上传到 ColdFusion 托管 (hostek.com/CF2016) 时它停止工作,因为 chr(2) returns 值“/u000299”,因此 API 响应错误。
我假设 ColdFusion 2016 改变了对 chr() 的处理,但是在两个版本的文档中,这个函数的处理没有变化。
似乎 CF/2016 正在根据 ASCII table 改变 (Escaped Unicode)。
所以呢?有人知道如何解决这个问题吗?
- 这与托管服务有关吗?
- Hostek.com 我的本地服务器有不同的编码器吗?
我希望有人对此有一些建议。谢谢
<cfset requestData = {"customer": "#customer#"
, "items":#empStruct#
, "payment_form":"#chr(2)#99"
, "payment_method": "#payment_method#"
, "use": "#use#"
, "folio_number": "#folio_number#"
, "series": "#series#"
}>
使用 Coldfusion 11 的 Serliaze 退出链(本地服务器 My_pc)
{
"payment_form": "99",
"series": "F",
"use": "G03",
"customer": "5d965ab97419177948b59a26",
"payment_method": "PPD",
"items": [
{
"quantity": 2,
"product": "5d9639d27419177948b59a0b"
},
{
"quantity": 15,
"product": "5d9639e07419177948b59a0c"
}
],
"folio_number": 7400
}
使用 ColdFusion 2016 序列化退出链(Coldfusion 托管 Hostek.com)
{
"payment_form": "\u000299",
"series": "F",
"use": "G03",
"customer": "5d9691f17419177948b59a68",
"payment_method": "PPD",
"items": [
{
"quantity": 500,
"product": "5d9d30bc08b8ad3f683e81bc"
},
{
"quantity": 500,
"product": "5d9d30c908b8ad3f683e81bd"
}
],
"folio_number": 7840
}
TL;DR;
与其尝试 "fix the fix",不如尝试使用 newer serialization features 之一
input = {"payment_form":"99"};
input.setMetadata( {payment_form: {type: "string"}} );
output = serializeJSON( input );
在 Development 中使用与 Prod 不同的版本总是会让人流泪......看看 CommandBox。它使得使用不同版本的 CF 变得非常容易。
chr(2) returns the value "/u000299"
无论如何.. serializeJSON() 函数将 chr(2)
转换为 /u0002
。但是,这似乎不是新行为。 CF 11 做同样的事情。与其尝试 "fix the fix",不如尝试使用 newer serialization features 之一:
Adobe ColdFusion (2016 release) Update 2 enables you to specify the
datatype information for keys in a struct. This is known as metadata.
将 payment_form
值显式声明为字符串,CF 会将其括在引号中而不是猜测它是一个数字。
输入:
input = {"payment_form":"99"};
input.setMetadata( {payment_form: {type: "string"}} );
output = serializeJSON( input );
writeDump( output );
结果:
{"payment_form":"99"}
此外,如果您是从查询对象构建它,CF2016 添加了两个新的应用程序设置,可以覆盖序列化查询的古怪默认值,使 generate a properly cased array of structures out of the box.
我目前使用 ColdFusion 11 作为本地服务器进行开发。
我有一个用 ColdFusion 序列化的 JSON 字符串。在字符串中,我必须在对象 "Payment_form" 中插入一个代码“99”。响应中所需的 Api 告诉我 Payment_form 对象是一个字符串。
了解使用 JSON 字符串和数字表示的 ColdFusion 序列化问题,请查看 Whosebug 并通过放置 "chr(2)".
找到解决方案问题已解决....但仅在 ColdFusion 11 中。当我将代码上传到 ColdFusion 托管 (hostek.com/CF2016) 时它停止工作,因为 chr(2) returns 值“/u000299”,因此 API 响应错误。
我假设 ColdFusion 2016 改变了对 chr() 的处理,但是在两个版本的文档中,这个函数的处理没有变化。
似乎 CF/2016 正在根据 ASCII table 改变 (Escaped Unicode)。
所以呢?有人知道如何解决这个问题吗?
- 这与托管服务有关吗?
- Hostek.com 我的本地服务器有不同的编码器吗?
我希望有人对此有一些建议。谢谢
<cfset requestData = {"customer": "#customer#"
, "items":#empStruct#
, "payment_form":"#chr(2)#99"
, "payment_method": "#payment_method#"
, "use": "#use#"
, "folio_number": "#folio_number#"
, "series": "#series#"
}>
使用 Coldfusion 11 的 Serliaze 退出链(本地服务器 My_pc)
{
"payment_form": "99",
"series": "F",
"use": "G03",
"customer": "5d965ab97419177948b59a26",
"payment_method": "PPD",
"items": [
{
"quantity": 2,
"product": "5d9639d27419177948b59a0b"
},
{
"quantity": 15,
"product": "5d9639e07419177948b59a0c"
}
],
"folio_number": 7400
}
使用 ColdFusion 2016 序列化退出链(Coldfusion 托管 Hostek.com)
{
"payment_form": "\u000299",
"series": "F",
"use": "G03",
"customer": "5d9691f17419177948b59a68",
"payment_method": "PPD",
"items": [
{
"quantity": 500,
"product": "5d9d30bc08b8ad3f683e81bc"
},
{
"quantity": 500,
"product": "5d9d30c908b8ad3f683e81bd"
}
],
"folio_number": 7840
}
TL;DR;
与其尝试 "fix the fix",不如尝试使用 newer serialization features 之一
input = {"payment_form":"99"};
input.setMetadata( {payment_form: {type: "string"}} );
output = serializeJSON( input );
在 Development 中使用与 Prod 不同的版本总是会让人流泪......看看 CommandBox。它使得使用不同版本的 CF 变得非常容易。
chr(2) returns the value "/u000299"
无论如何.. serializeJSON() 函数将 chr(2)
转换为 /u0002
。但是,这似乎不是新行为。 CF 11 做同样的事情。与其尝试 "fix the fix",不如尝试使用 newer serialization features 之一:
Adobe ColdFusion (2016 release) Update 2 enables you to specify the datatype information for keys in a struct. This is known as metadata.
将 payment_form
值显式声明为字符串,CF 会将其括在引号中而不是猜测它是一个数字。
输入:
input = {"payment_form":"99"};
input.setMetadata( {payment_form: {type: "string"}} );
output = serializeJSON( input );
writeDump( output );
结果:
{"payment_form":"99"}
此外,如果您是从查询对象构建它,CF2016 添加了两个新的应用程序设置,可以覆盖序列化查询的古怪默认值,使 generate a properly cased array of structures out of the box.