【发布时间】:2014-02-06 00:30:32
【问题描述】:
我得到了这个代码来实现我的需要:
import json
json_data = []
with open("trendingtopics.json") as json_file:
json_data = json.load(json_file)
for category in json_data:
print category
for trendingtopic in category:
print trendingtopic
这是我的 json 文件:
{
"General": ["EPN","Peña Nieto", "México","PresidenciaMX"],
"Acciones politicas": ["Reforma Fiscal", "Reforma Energética"]
}
但是我正在打印这个:
Acciones politicas
A
c
c
i
o
n
e
s
p
o
l
i
t
i
c
a
s
General
G
e
n
e
r
a
l
我想得到一个字典作为字符串的键并得到一个列表作为值。然后迭代它。我怎样才能完成它?
【问题讨论】:
-
你的意思是
for trendingtopic in json_data[category]:在你的内部循环中吗?
标签: python json dictionary