How to Parse JSON Returned in ColdFusion

前端 未结 3 2011
隐瞒了意图╮
隐瞒了意图╮ 2021-01-15 12:03

I\'m sure this is a relatively simple question, but I can\'t seem to find a simple answer anywhere online.

I have a few lines of JSON returned by a cfhttp POST with

相关标签:
3条回答
  • 2021-01-15 12:41

    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

    0 讨论(0)
  • 2021-01-15 12:46

    Just parsing your cfhttp result with deserializeJSON()

    <cfset getResult = deserializeJSON(result_Variable.filecontent)>
    

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

    0 讨论(0)
  • 2021-01-15 13:01

    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.

    0 讨论(0)
提交回复
热议问题