[英]Get value and define it in a nested dictionary in json, python
Hi, I'm trying to use the value in a nested dictionary in a json file by python.嗨,我正在尝试在 python 的 json 文件中使用嵌套字典中的值。 The value can be printed, but cannot give the value to the parameter... I don't know what's wrong with it.
可以打印值,但是不能给参数赋值……不知道有什么问题。 I'm a novice on coding, Thank you guys~
我是新手,谢谢大家~
a part of json file: json 文件的一部分:
{
"grinning": {
"keywords": ["face", "smile", "happy", "joy"],
"char": "😀",
"category": "people"
},
"grin": {
"keywords": ["face", "happy", "smile", "joy"],
"char": "😁",
"category": "people"
},
"joy": {
"keywords": ["face", "cry", "tears", "weep", "happy", "haha"],
"char": "😂",
"category": "people"
},
"smiley": {
"keywords": ["face", "happy", "joy", "haha"],
"char": "😃",
"category": "people"
},
"smile": {
"keywords": ["face", "happy", "joy", "funny", "haha", "laugh", "like"],
"char": "😄",
"category": "people"
},
"sweat_smile": {
"keywords": ["face", "hot", "happy", "laugh"],
"char": "😅",
"category": "people"
},
"laughing": {
"keywords": ["happy", "joy", "lol", "satisfied", "haha", "face", "glad"],
"char": "😆",
"category": "people"
},
"innocent": {
"keywords": ["face", "angel", "heaven", "halo"],
"char": "😇",
"category": "people"
},
}
Your code worked for me:你的代码对我有用:
for key,value in Emoji_data.items():
Emoji_name = key
Emoji_value = value['keywords']
Emoji_char = value['char']
print(f"Name: {Emoji_name} | Value:{Emoji_value} | Emoji:{Emoji_char}")
Verify if your Emoji_data is consistent, you can try this validator (or any other json validator on web): https://jsonformatter.curiousconcept.com/验证您的 Emoji_data 是否一致,您可以尝试此验证器(或网络上的任何其他 json 验证器): https://jsonformatter.curiousconcept.com/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.