ColdFusion 10 REST API: How to parse JSON in body of payload

与世无争的帅哥 提交于 2019-12-05 15:56:10

After a lot of research, it doesn't look like there's a native way for ColdFusion 10's REST API request handler to parse JSON requests automatically for us. We need to do this manually as follows:

<cfset var json = ToString(GetHttpRequestData().content) />
<cfif !IsJSON(json)>
    <cfthrow errorCode="400" type="ArgumentException" message="#"Invalid JSON string: " & json#" />
</cfif>

<cfset var jsonObject = DeserializeJSON(json) />
pravins

You can also try

VARIABLES.postJSON = StructNew();
StructInsert(VARIABLES.postJSON, 'parameter1','xxx');

then user #SerializeJSON(VARIABLES.postJSON)#

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!