所以我在 JSON 中有這段代碼:
[ {
"idema" : "0009X",
"lon" : 0.963335,
"fint" : "2022-05-03T13:00:00",
"prec" : 0.0,
"alt" : 406.0,
"vmax" : 5.8,
"vv" : 2.2,
"dv" : 102.0,
"lat" : 41.213894,
}}
我想獲取這些欄位lat并long在 JOSN 中像這樣合并它們:
"longlat": "POINT(23.0 33.0)",
我正在像這樣決議檔案:
meteo_station_list = JSON.parse(File.read('meteo_stations.json'))
meteo_station_list.each do |station|
MeteoStationAemet.create(station.to_h)
謝謝!
uj5u.com熱心網友回復:
1-您需要將此 Json 轉換為哈希
meteo_station_list = JSON.parse(File.read('meteo_stations.json')).with_indifferent_access
2-您只需要遍歷哈希并使用此代碼段
def genrate_point
meteo_station_list.each do |station|
station[:longlat] = "point(#{station[:lat]} #{station[:lon]}"
station.except!(:lat,:lon)
end
end
查官方除了檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/474210.html
上一篇:如何在.slimJavascript函式中使用rails條件?
下一篇:Ruby的Base64.urlsafe_encode64(Digest::SHA256.hexdigest(STRING))的Python等價物是什么?
