[英]unhashable type: dict with test JSON
当我尝试在 python 解释器中测试一些 JSON 时,出现错误。 我不知道为什么。
Traceback (most recent call last):
File "<stdin>", line 6, in <module>
TypeError: unhashable type: 'dict'
JSON:(不起作用)
b = {
'data':{
'child':{
{'kid1':'one'},
{'kid2':'two'},
{'kid3':'three'}
},
'child':{
{'kid4':'four'},
{'kid5':'five'},
{'kid6':'six'}
}
}
}
JSON:(有效)
a = {
"slate" : {
"id" : {
"type" : "integer"
},
"name" : {
"type" : "string"
},
"code" : {
"type" : "integer",
"fk" : "banned.id"
}
},
"banned" : {
"id" : {
"type" : "integer"
},
"domain" : {
"type" : "string"
}
}
}
您的第一个示例不起作用的原因是每个“子”键都有一个声明为它的值而不是列表的字典,就像您想要的那样。 用[
替换{
它将起作用。
'child': {
{'kid1':'one'},
{'kid2':'two'},
{'kid3':'three'},
},
应该:
'child': [
{'kid1':'one'},
{'kid2':'two'},
{'kid3':'three'},
],
换句话说,你说“孩子”是一本字典,但没有给出字典。
当我的 JSON 格式略有错误时,我想到了这个问题:
json = {
{
"key": "value",
"key_two": "value_two"
}
}
应该:
json = {
"key": "value",
"key_two": "value_two"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.