我得到了这个代码来实现我的需求:
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
我想得到一个字典是字符串键并得到一个列表作为值.然后迭代它.我怎么能完成它?