【发布时间】:2017-07-24 16:59:08
【问题描述】:
我在 ColdFusion 中编写了一个 Web 服务 (cfc),它接受 JSON 输入数据,并且在身份验证后返回 http 状态代码。 我的问题是 - 如何在 FORM 范围内的 ColdFusion 中捕获/接受 JSON 数据???
我已经写了两种接受 JSON 的方法,但我不确定。谁能帮忙。
第一种方式:
<cfscript>
record=deserializeJSON(
'{
"customerId": #Form.CustomerID#,
"userName": "#Form.userName#",
"password": "#Form.Password#"
}'
);
this.customerid = record.customerId;
this.userName = record.userName;
this.password = record.password;
</cfscript>
我正在解析输入 json 并将其放入结构中,然后在变量中设置参数。
第二种方式:
<cfif (cgi.content_type EQ "application/json")>
<cfset record = deserializeJSON(ToString(getHTTPRequestData().content))>
<cfscript>
this.customerId = record.customerId;
this.userName = record.userName;
this.password = record.password;
</cfscript>
</cfif>
谁能帮我理解如何在 ColdFusion 中捕获 JSOn 输入数据?
【问题讨论】:
-
我正在查看您对
deserivalizeJSON()的使用,我认为您走错了路。我认为您想构建一个结构,然后对其进行序列化。
标签: json web-services coldfusion cfc