【发布时间】:2023-03-30 14:09:01
【问题描述】:
这是我的工作示例
jsonData = {
"3": {
"map_id": "1",
"marker_id": "3",
"title": "Your title here",
"address": "456 Example Ave",
"desc": "Description",
"pic": "",
"icon": "",
"linkd": "",
"lat": "3.14",
"lng": "-22.98",
"anim": "0",
"retina": "0",
"category": "1",
"infoopen": "0",
"other_data": ["0"]
},
"4": {
"map_id": "1",
"marker_id": "4",
"title": "Title of Place",
"address": "123 Main St, City, State",
"desc": "insert description",
"pic": "",
"icon": "",
"linkd": "",
"lat": "1.23",
"lng": "-4.56",
"anim": "0",
"retina": "0",
"category": "0",
"infoopen": "0",
"other_data": ["0"]
}
我很难获得title 和address 密钥。这是我尝试过的:
for each in testJson:
print(each["title"])
我收到以下错误TypeError: string indices must be integers。我不明白为什么这不起作用。
我已经尝试了很多变体来获取关键数据,但我就是无法让它发挥作用。我也无法真正更改原始 JSON,因为我真正的 JSON 数据是一个巨大的文件。我在 stackoverflow 上查看了类似格式的 JSON 示例(例如,here),但结果很短。我认为我的 JSON 的格式化方式有问题,因为我之前用上面的代码解析过 JSON 没有任何问题。
【问题讨论】: