2017-02-23 10 views
-1

AngelsJSを使用してbandsintown.comから実際のイベントを取得しているGrailsコンサートアプリケーションを開発しています。JSONデータをMySQLデータベースに追加

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

私はイベントを取得することができていると私は今、オブジェクトに各イベントを回し、私のデータベースに追加したいので、私は彼らのその後の詳細とその他もろもろとイベントごとに独自のページを持つことができます。

このようなことを行う方法について私に指導を提供できる人はいますか?

ありがとうございました!

+2

を各反復を解析し、あなたが実際に文字列としてドメインクラスでプットを必要とすること、各キーのようので、この上のURLを上からエントリ全体ではしているようです**広い**質問。 – Mistalis

+0

次の複製のようです:http://stackoverflow.com/questions/35041851/inserting-json-object-into-mysql-table-with-angular-php –

+0

'JSON.stringify(result);'を使用してこれを挿入しますあなたのデータベースのそれぞれの列の文字列。読み込み中に 'JSON.parse(jsonstring): ' –

答えて

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 

...そして上記のコードで

{"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 
関連する問題