How to Parse JSON Returned in ColdFusion

一个人想着一个人 提交于 2019-12-01 10:54:33

Converts a JSON (JavaScript Object Notation) string data representation into CFML data, such as a CFML structure or array.

https://wikidocs.adobe.com/wiki/display/coldfusionen/DeserializeJSON

Just parsing your cfhttp result with deserializeJSON()

<cfset getResult = deserializeJSON(result_Variable.filecontent)>

and you can get the href value using "#getResult.href#"

Leigh

I forgot to mention that I'm using ColdFusion MX

Ah, that makes a very big difference! (Unless otherwise stated in the tags, most people will assume a more recent version, like CF9+).

JSON support was not added until CF8. If you search, there are still some older udf/cfc's for handling JSON out there. For example:

  • JSONDecode at http://www.cflib.org says it works with MX6

  • JSONUtil.cfc works with MX7+. It might work with MX6 out of the box, or with a few modifications. This thread has a description of how to encode with JSONUtil. Decoding should be equally simple. Just create an instance and invoke deserializeJSON, ie:

    <!--- not tested --->
    <cfset util = createObject("component", "path.to.JSONUtil")>
    <cfset result = util.deSerializeJSON(yourJSONString)>
    

That said, ColdFusion MX is a bit long in the tooth and no longer supported. You should seriously consider upgrading or switching to the open source Railo engine.

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