Last active
January 3, 2021 20:32
-
-
Save robertz/f82feb5dd6ae1b3701f8f9c5c0d7b7a8 to your computer and use it in GitHub Desktop.
Using org.json.XML to convert XML to JSON inside a ColdBox event handler. The org.json java library will need to be downloaded to the ColdBox /lib folder or added to the server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component extends="coldbox.system.EventHandler" { | |
property name = "SpiderService" inject; | |
function xmlToJson (event, rc, prc) { | |
var u = event.getValue("u", ""); | |
prc['data'] = {}; | |
if(u.len()){ | |
var obj = createObject("java", "org.json.XML"); | |
cfhttp(url = rc.u, method = "get"); | |
if(isXML(cfhttp.fileContent)) prc.data.append(deserializeJSON(obj.toJSONObject(cfhttp.fileContent, true))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment