-1

I'm developing a Grails concert application where I am acquiring the actual events from bandsintown.com using AngularJS.

 $.getJSON("http://api.bandsintown.com/events/search.json?&api_version=2.0&app_id=FYP&location=Dublin,Ireland", function(result) 

I am able to retrieve the events and I now want to turn each event into an object and add them to my database, so I can have a unique page for each event with their subsequent details and whatnot.

Is anyone able to provide me guidance on how to do such a thing?

Thank you!

5
  • 2
    Seems to be a broad question.
    – Mistalis
    Feb 23, 2017 at 15:13
  • Seems like an duplicate of: stackoverflow.com/questions/35041851/… Feb 23, 2017 at 15:15
  • Use JSON.stringify(result); and insert this string in your database at respective column.While reading use JSON.parse(jsonstring):
    – vinoth h
    Feb 23, 2017 at 15:17
  • @Mistalis I did recognise that as I wrote my query. After about an hours worth of research, I found there to be a lot of information. So I decided to strip my question to its most basic form and ask it as I did.
    – TS.
    Feb 23, 2017 at 15:24
  • Welcome to SO. It's helpful, when you write a question, if you show an example of data and the result you want. Please edit your question to do that. By the way, I guess the JSON object you retrieved contains a collection of multiple events, and you want to insert each event in its own row of a table. You'll need to write code to do that -- to iterate over the events. Or you can treat your JSON object as a text string and just slosh it into a column of a table. But good luck searching it in that case.
    – O. Jones
    Feb 23, 2017 at 15:37

1 Answer 1

0

I wrote something a while ago as a plugin which may help you get your head around what you need to do :

private String viewTicketField(String jiraserver, String jirauser,String jirapass, String url, String customField) {
    if (url.endsWith('undefined')) {
        return
    }

    String output=''

    try {
        HBuilder hBuilder=new HBuilder()
        RESTClient http = hBuilder.httpConn(jiraserver, jirauser, jirapass,httpConnTimeOut,httpSockTimeOut)
        http.request(Method.GET ) { req ->
            uri.path = url
            response.success = { resp, json ->
                log.info "Process URL Success! ${resp.status}  "
                def result=JSON.parse(json.toString())
                if (result.fields."customfield_${customField}") {
                    output=result.fields."customfield_${customField}"
                }
            }
            response.failure = { resp ->
                log.error "Process URL failed with status ${resp.status}"
            }
        }
    }
    catch (HttpResponseException e) {
        log.error "Failed error: $e.statusCode"
    }
    return output
}

HBuilder class can be found in src

After you have connected and got back your JSON response you then parse each line

You create a new domain class

String url 
String datetime
String app_id
String ticket_url 

... and so on this is an entire entry from above url so for each key that you actually require put in domain class as strings then parse each iteration with above code

{"id":13926481,"url":"http://www.bandsintown.com/event/13926481?app_id=FYP","datetime":"2017-02-23T17:00:00","ticket_url":"http://www.bandsintown.com/event/13926481/buy_tickets?app_id=FYP\u0026came_from=233","artists":[{"name":"Rackhouse Pilfer","url":"http://www.bandsintown.com/RackhousePilfer","mbid":null}],"venue":{"id":3334537,"url":"http://www.bandsintown.com/venue/3334537","name":"Convention Centre","city":"Dublin","region":"07","country":"Ireland","latitude":53.3500292,"longitude":-6.2385286},"ticket_status":"unavailable","on_sale_datetime":null

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.