我不知道为什么这会自我重复3次。代码blow打印888888888次3次。我只想打印一次
我使用这个方法的原因是,我将使用多个类型、id和属性。
jsondata = { "data": [
{
"type": "product",
"id": "888888888",
"attributes": {
"ean": "888888888",
"name": "product name",
}
}
]
}
jsonObject = jsondata
for inner_dict in jsonObject["data"]:
for key,value in inner_dict.items():
test = inner_dict["attributes"]["ean"]
print (test)发布于 2021-06-17 12:44:24
你在不必要的重复着这段话。
松开第二个循环就可以了。
jsondata = {
"data": [
{
"type": "product",
"id": "888888888",
"attributes": {
"ean": "888888888",
"name": "product name",
}
}
]
}
jsonObject = jsondata
for inner_dict in jsonObject["data"]:
test = inner_dict["attributes"]["ean"]
# for key,value in inner_dict.items():
# print(key, value)
print (test)https://stackoverflow.com/questions/68019506
复制相似问题