2

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 an image URL that I'd like to parse out and display in my ColdFusion page:

{
    "href": "http://server.arcgisonline.com/arcgis/rest/directories/arcgisoutput/ESRI_StreetMap_World_2D_MapServer/_ags_map734a6ad322dd493e84499d78f027d841.png",
    "width": 854,
    "height": 493,
    "extent": {
        "xmin": -8285407.015562119,
        "ymin": 4944008.4197687358,
        "xmax": -8220129.7934066672,
        "ymax": 4981691.8747132765,
        "spatialReference": {
            "wkid": 102100,
            "latestWkid": 3857
        }
    },
    "scale": 288895.27714399656
}

How can I make "href"'s value a part of a variable in ColdFusion, and/or potentially have a button linked to downloading it?

EDIT: I forgot to mention that I'm using ColdFusion MX - also known as version 6 - and hence why I cannot use the DeserializeJSON listed on Adobe's page

Leigh
  • 28,765
  • 10
  • 55
  • 103
jaychman
  • 31
  • 1
  • 7
  • http://help.adobe.com/livedocs/coldfusion/8/htmldocs/help.html?content=functions_c-d_43.html –  Aug 07 '14 at 19:32
  • 3
    What have you tried? I do not mean this sarcastically, but .. a five second search on "How to Parse JSON ColdFusion" should have turned up multiple references to the `deserializeJSON`function :) Did you try it? Please post your code and any error messages. (BTW, If you are new to StackOverflow, it works a little differently than a forum. Please see the FAQ's as well: [Ask]). – Leigh Aug 07 '14 at 19:49

3 Answers3

4

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

Henry
  • 32,689
  • 19
  • 120
  • 221
2

Just parsing your cfhttp result with deserializeJSON()

<cfset getResult = deserializeJSON(result_Variable.filecontent)>

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

Sathish Chelladurai
  • 670
  • 1
  • 8
  • 23
2

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.

Community
  • 1
  • 1
Leigh
  • 28,765
  • 10
  • 55
  • 103