我的geoJSON看起来是这样
{
"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": [{
"type": "Feature",
"properties": {
"value1": "abc",
"value2": 0,
"value3": 0.99,
"value4": "def",
"value5": "882.3",
"value6": 12,
},
"geometry": {
"type": "Point",
"coordinates": [1, 1]
}
}
]
}我想访问properties,并检查一下values中的key
for features in geoJsonPoints["features"]:
for interesting in features["properties"]["value1"]:
print interesting
print "!"我得到了
一个 好了! B 好了! C 好了!
为什么?!好像我的循环不给我一本字典?!
如果我这么做
for features in geoJsonPoints["features"]:
for interesting in features["properties"]:
print type(intereseting)
print interesting我得到了
类型'unicode‘ value1 类型'unicode‘ value2 ..。
为什么那不是一本字典?而且,如果它不是字典,为什么我可以访问"unicode“后面的值,就像在我展示的第一个循环中一样?!
发布于 2016-04-20 22:16:50
features["properties"]["value1"]指向逐个字符迭代的abc字符串。相反,您可能打算遍历properties字典:
for property_name, property_value in features["properties"].items():
print(property_name, property_value)或者,您可以遍历字典键:
for property_name in features["properties"]:
print(property_name, features["properties"][property_name])请参阅有关字典和循环技术的更多信息:
https://stackoverflow.com/questions/36756144
复制相似问题