将json传递给cfhttpparam
我正在使用ColdFusion 2016,下面是我正在做的:将json传递给cfhttpparam,json,coldfusion,Json,Coldfusion,我正在使用ColdFusion 2016,下面是我正在做的: <cfhttp method="put" url="https://www.colorfulapi.com/testpage/#arguments.Name#" username="#request.APIusername#" password="#request.APIToken#" result="results"> <cfhttpparam type="header" name="Content-Typ
<cfhttp method="put" url="https://www.colorfulapi.com/testpage/#arguments.Name#" username="#request.APIusername#" password="#request.APIToken#" result="results">
<cfhttpparam type="header" name="Content-Type" value="application/json">
<cfif isStruct(arguments.structform) AND !StructIsEmpty(arguments.structform)>
<CFHTTPPARAM VALUE="'#serializeJSON(stFields)#'" TYPE="body">
</cfif>
</cfhttp>
如果它使用serializeJSON
进入cfhttpparam,它将显示以下内容:
"error":"JSON error: 822: unexpected token at ''{\"ONE\":{\"GROUP\":\"my group\"}}''"}
我在POSTman中尝试了相同的代码,但在POSTman
中,对于JSOn
发送,我必须使用原始的正文,并选择内容作为application/JSOn
,它在那里起作用
这就是我生成stfield的方式
<cfset stFields = StructNew()>
<cfset stFields.one = arguments.structform>
<cfdump var="'#serializeJSON(stFields)#'">
删除单引号:
<CFHTTPPARAM VALUE="#serializeJSON(stFields)#" TYPE="body">
不,不是Alex,让我写下如何生成
stFields
。我正在编辑我的问题如果我删除单个代码,我会得到一个错误,将json字符串传递给api是无效的,这让人很困惑,{“ONE”:{“GROUP”:“my GROUP”}}
是无效的json<代码>{“一”:{“组”:“我的组”}另一方面,是。API到底期望什么?这是我从POSTMAN API发送的内容,它可以工作http://prntscr.com/e72nxx
@weqsd-旧方法是使用结构表示法,而不是点表示法,即structName[“keyName”]=value
。如果使用速记结构语法,请参见中的示例。另请参见CF11+中的更多选项。
<CFHTTPPARAM VALUE="#serializeJSON(stFields)#" TYPE="body">
<CFHTTPPARAM VALUE="#stFields#" TYPE="body">