Using JSON Data with Coldfusion -
i've worked json data in past - 'fudging' way solution, , not understanding why or how things work. i've come across issue data being returned looks different i've seen before, , can't find examples match it.
here's example of data returned (via api);
{"domain.co.uk":{"status":"available","classkey":"thirdleveldotuk"},"domain.net":{"status":"available","classkey":"dotnet"},"domain.com":{"status":"available","classkey":"domcno"}}
on front-end, need return -
- domain.co.uk - available
- domain.net - available
- domain.com - available
because 'domain.com' etc value change, can't map names (although 3 'rows' returned)
i've checked every cf book own, , read online cf docs, i'm totally @ loss start one!
pointers appreciated!
if run deserializejson(data), you'll see end structures nested structures. so, can loop through struct, grab keys , grab key's status. in json terms, json object has nested objects.
<cfset data = deserializejson(apidata) /> <cfset formatteddata = [] /> <cfset tmp = {} /> <cfloop collection=#data# item="domain"> <cfset tmp.domain = domain /> <cfset tmp.status = data[domain]["status"] /> <cfset arrayappend(formatteddata,duplicate(tmp)) /> </cfloop> <cfdump var=#formatteddata# />
Comments
Post a Comment