I’m developing an application which extracts information about musical events from Last.fm API.
However, for some reason the application is parsing only the first two events from the XML file and I can not figure out why. Any help?
This is the code:
def resultList = []
if(connection.responseCode == 200){
def xml = connection.content.text
def lfm = new XmlSlurper().parseText(xml)
lfm.events.event.each {
def result = [:]
result.eventId = it.id as String
result.eventTitle = lfm.events.event.find { it.'id' == result.eventId }.title as String
resultList << result
}
I just found that the bug was in the save{} closure of the Controller class. The following is the code with the bug:
So the problem was that I was redirecting the action “show” inside the each{} closure. And for some reason that I’m still not sure, it was throwing an exception after the second iteration of the each{} loop. So all I had to do was to call the redirect method outside the each{} closure, like this:
I’m still curious why it was throwing the exception only after the second iteration, but anyway, the problem is solved. Thanks!