'{"name": "Polygon Sample", "geo_json": {"type": "Feature", "properties": {}, "geometry": {"type": "Polygon", "coordinates": [[ [-121.1958, 37.6683], [-121.1779, 37.6687], [-121.1773, 37.6792], [-121.1958, 37.6792], [-121.1958, 37.668]]]}}}' 這是來自 csv 檔案的一列值,我得到的字串。我只需要提取坐標 -> [[-121.1958, 37.6683], [-121.1779, 37.6687], [-121.1773, 37.6792], [-121.1958, 37.6792], [-121.1958, 37.668]]。我該如何解決這個問題?使用 eval() 我該怎么做?
uj5u.com熱心網友回復:
在python中,您可以使用json庫將字串轉換為dict ,然后訪問坐標
import json
input_data = '{"name": "Polygon Sample", "geo_json": {"type": "Feature", "properties": {}, "geometry": {"type": "Polygon", "coordinates": [[[-121.1958, 37.6683], [-121.1779, 37.6687], [-121.1773, 37.6792], [-121.1958, 37.6792], [-121.1958, 37.668]]]}}}'
data_dict = json.loads(input_data)
print(data_dict["geo_json"]["geometry"]["coordinates"])
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/513608.html
