我写了一个web服务(cfc)在ColdFusion接受JSON输入数据,我在验证后返回http状态码。 我的问题是 - 如何在ColdFusion中,在FORM范围内捕获/接受JSON数据?JSON输入到ColdFusion webservice + RestFul
我写了两种接受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>
谁能请帮助我了解如何捕捉JSON输入数据的ColdFusion?
我在看你的使用deserivalizeJSON的'() '我觉得你走错了路。我想你想建立一个结构体,然后序列化它。 –