【发布时间】:2021-11-10 17:28:33
【问题描述】:
我有以下代码用于打开上述 json 文件并提取数据。但是,我只想要坐标数据,但代码给了我以下错误。
TypeError: string indices must be integers.
如何只打印坐标数据?
{
"type": "Polygon",
"coordinates": [
[
[
-5.84731,
60.5832
],
[
-5.93843,
60.5832
],
[
-2.39097,
60.5832
],
[
-2.39097,
60.5843
],
[
-2.75097,
60.5823
]
]
]
}
import json
f = open('allData.json')
data = json.load(f)
print(data['type']['coordinate'])
f.close()
【问题讨论】: