我得到了实现我的需要的代码:
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文件:
^{pr2}$不过,我要把这个打印出来:
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
我想得到一个字典,把键串起来,得到一个列表作为值。然后迭代它。我怎样才能做到呢?在
json_data是一个字典。在第一个循环中,迭代字典的键列表:
类别将包含密钥字符串-通用和Acciones politica。在
您需要替换此循环,该循环迭代键的字母:
^{pr2}$,以便在字典元素上迭代:
我将使用字典的
.iteritems()
方法,该方法返回键/值对:相关问题 更多 >
编程相关推荐