在python中循环使用json键

在python中循环使用json键,python,json,Python,Json,所以。。。我创建了一个不和谐的web钩子调用程序,我让JSON阅读器知道它必须发送什么web钩子。我想打印它将要发送的消息,但发生了以下情况:它没有给我输出。 我的代码: main.py: import json from collections import Counter #import requests with open('data.json') as json_file: data = json.load(json_file) for hallo in range(0

所以。。。我创建了一个不和谐的web钩子调用程序,我让JSON阅读器知道它必须发送什么web钩子。我想打印它将要发送的消息,但发生了以下情况:它没有给我输出。 我的代码:

main.py:

import json
from collections import Counter
#import requests

with open('data.json') as json_file:
    data = json.load(json_file)
    for hallo in range(0, len(data) - 1):
        stringSmall = "<:" + data[str(hallo + 1)]['emojiName'] + ":" + data[str(hallo + 1)]['serverID'] + ">"
        print(stringSmall)
我想打印一篇以下内容的作文:

“”

我想要的输出应该如下所示: 但我没有得到任何结果

请帮忙,我正在努力思考发生了什么事

请使用
.items()
反复浏览字典:

import json
with open('data.json') as json_file:
    data = json.load(json_file)

    for k, values in data.items():
        # k == 1
        stringSmall = "<:" + values['emojiName'] + ":" + values['serverID'] + ">"
        print(stringSmall)
导入json
将open('data.json')作为json_文件:
data=json.load(json_文件)
对于k,data.items()中的值:
#k==1
stringSmall=“”
印刷品(小)
输出:



阅读下面的内容。它从
开始
结束
,但不包括
结束
。当
len(数据)
1
时,
范围(0,len(数据)-1)
将具有零元素。将range调用更改为
range(0,len(data))
。OP的迭代
range()
并选择特定元素的技术确保每次的顺序相同。给定的dict是无序的,每次迭代
items()
会给出相同的顺序吗?因为Python3.7
dict
是有序的。
import json
with open('data.json') as json_file:
    data = json.load(json_file)

    for k, values in data.items():
        # k == 1
        stringSmall = "<:" + values['emojiName'] + ":" + values['serverID'] + ">"
        print(stringSmall)
<:7777:999999999999999999>