问题是} {被自动添加到图像和ID 2之间。我是否应该添加检查以防止这种情况? 生成json文件和生成的json文件的Python代码:
def generate_pokemon_image_db():
with open("Image.json", "w") as file:
for i in range(1, 3):
p = requests.get('https://pokeapi.co/api/v2/pokemon-species/{}'.format(i))
pk = p.json()
imgr_result = imgr_client.upload_from_path("D:\\json_generator\\Convert\\{}.png".format(i), config=None, anon=True)['link']
data = {"Id": pk['id'],
"Name": pk['name'],
"Image": imgr_result}
json.dump(data, file, indent=1) ```
{
"Id": 1,
"Name": "bulbasaur",
"Image": "https://i.imgur.com/UBMWUCJ.png"
}{
"Id": 2,
"Name": "ivysaur",
"Image": "https://i.imgur.com/0cFH8Bu.png"
}