将JSON数据添加到MySQL数据库

时间:2017-02-23 15:12:21

标签: mysql angularjs json database grails

我正在开发一个Grails音乐会应用程序,我使用AngularJS从bandsintown.com获取实际事件。

RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", true);
key.SetValue("kashif", 1, RegistryValueKind.DWord);

我能够检索事件,现在我想将每个事件转换为一个对象并将它们添加到我的数据库中,这样我就可以为每个事件创建一个唯一的页面及其后续的详细信息等等。

是否有人能够就如何做这样的事情向我提供指导?

谢谢!

1 个答案:

答案 0 :(得分:0)

我刚才写了一些插件,可以帮助你了解你需要做的事情:

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类可以在src

中找到

在连接并获得JSON响应之后,然后解析每一行

您创建了一个新的域类

String url 
String datetime
String app_id
String ticket_url 

...依此类推,这是来自url的整个条目,因此对于您实际需要的每个将域类作为字符串放入,然后用上面的代码解析每次迭代

{"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