Re: [json-lib-user] Groovy HTTPBuilder + JSON Parsing Error
Brought to you by:
aalmiray
From: Ronald R. D. <ron...@gm...> - 2009-03-13 14:30:23
|
I figured out what it is and as far as I am concerned it is broken in the JSON. What was happening is that I had spaces: at the beginning of the JSON string. So for example, it looked like: { "node" : but if I changed it to be: { "node" : Then it worked. Now, I just need to understand how to deal with the parsed stream. I tried the following: // parse the JSON response object: json.responseData.each { println " ${it}" } I also tried: // parse the JSON response object: json.responseData.node.each { println " ${it}" } But I get back NULL data both cases. Thoughts? -- Ron DiFrango http://rdifrango.blogspot.com/ On Fri, Mar 13, 2009 at 9:59 AM, Ronald R. DiFrango <ron...@gm...> wrote: > All, > > I am attempting to do the following with Groovy: > > http.request( GET, JSON ) { > url.query = [ > sourceName:'avm://portal--admin/-1;www;avm_webapps;ROOT;DCP_4963.JPG', > destName:'HHMI Documents/images', name:'ronCopy.jpg', remove:'false' ] > > requestContentType : JSON > > // response handler for a success response code: > response.success = { resp, json -> > println resp.statusLine > > // parse the JSON response object: > json.responseData.results.each { > println " ${it.titleNoFormatting} : ${it.visibleUrl}" > } > } > > // handler for any failure status code: > response.failure = { resp -> > println "Unexpected error: ${resp.statusLine.statusCode} : > ${resp.statusLine.reasonPhrase}" > } > } > > The response JSON looks like the following: > > { "node" : > { > "projectOverviewLocation" : > "workspace://SpacesStore/d83b8a9b-8685-40d4-b045-5def043b85a5" > } > } > > > Which to me looks like valid JSON, but I get the following exception: > > Exception thrown: Invalid JSON String > > net.sf.json.JSONException: Invalid JSON String > at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:143) > at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:103) > at net.sf.json.groovy.JsonSlurper.parseText(JsonSlurper.java:78) > at groovyx.net.http.ParserRegistry.parseJSON(ParserRegistry.java:185) > at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:461) > at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:407) > at groovyx.net.http.HTTPBuilder.request(HTTPBuilder.java:360) > at ConsoleScript52.run(ConsoleScript52:9) > > Any reason why that might be occurring? > > -- > Ron DiFrango > http://rdifrango.blogspot.com/ > |