我正在接收來自GET api調用的響應,該響應在我的數據庫中映射爲1:1。響應看起來像這樣:Rails - 我應該使用哪種數據類型來將數組存儲在數據庫中
response = {
"status": "live",
"templates": {},
"responses": 0,
"creator": "Marketing",
"publish_url": "https://fluidsurveys.com/account/surveys/403975/publish/",
"quota_start_date": null,
"updated_at": "2014-01-18T16:05:20",
"online_url": "http://fluidsurveys.com/surveys/marketing/tampa-bob-gilbertson-3084-nme-survey-emai/",
"deploy_uri": "http://fluidsurveys.com/surveys/marketing/tampa-bob-gilbertson-3084-nme-survey-emai/",
"settings_url": "https://fluidsurveys.com/account/surveys/403975/settings/",
"groups": [],
"quota_end_date": null,
"offline_url": "http://fluidsurveys.com/surveys/marketing/tampa-bob-gilbertson-3084-nme-survey-emai/offline/",
"responses_url": "https://fluidsurveys.com/account/surveys/403975/responses/",
"style_url": "https://fluidsurveys.com/account/surveys/403975/theme/",
"id": 403975,
"upgrade_url": "https://fluidsurveys.com/account/surveys/403975/upgrade-version/",
"name": "Bob Gilbertson 3084453 NME Survey Emai",
"uri": "https://fluidsurveys.com/api/v2/surveys/403975/",
"invites_url": "https://fluidsurveys.com/account/surveys/403975/publish/invites/",
"created_at": "2014-01-17T21:47:52",
"tags": [
"austin",
"nme"
],
"preview_url": "http://fluidsurveys.com/surveys/marketing/tampa-bob-gilbertson-3084-nme-survey-emai/?TEST_DATA=",
"report_url": "https://fluidsurveys.com/account/surveys/403975/reports/",
"version": 4.0,
"updated_at_text": "10:05 am",
"edit_url": "https://fluidsurveys.com/account/surveys/403975/edit/"
}
正如你所看到的,有我得到回來了,這響應了幾個陣列。例如,我想在我的Survey
型號的數據庫中存儲response["tags"]
。
然而,當我嘗試,我得到一個錯誤:
TypeError (can't cast Array to string):
我怎樣才能解決這個問題呢?我是否應該將string
的數據類型更改爲其他內容,或者還有其他需要做的事情來允許將數組存儲在數據庫中?另外,作爲一個獎勵,將數組存儲在數據庫不良實踐中?
我在最後添加了一個簡短的解釋。 – lipanski