Json 如何打印哪个键是“QUOTE”;“失踪”;我得到的是哪把钥匙;假;下面的脚本有什么反应?

Json 如何打印哪个键是“QUOTE”;“失踪”;我得到的是哪把钥匙;假;下面的脚本有什么反应?,json,python-3.x,Json,Python 3.x,我的剧本 def validate_record_schema(): """Validate that the 0 or more Payload dicts in record use proper types""" err_path = "root" try: for record in original_data: device = record["Device"] icon = device[

我的剧本

def validate_record_schema():
    """Validate that the 0 or more Payload dicts in record
    use proper types"""
    err_path = "root"
    try:
        for record in original_data:
            device = record["Device"]
            icon = device["Icon"]

            key_data = ((device["ManualAdded"], bool), (device["Location"], (str, type(None))),
                        (device["Version"], (str, type(None))), (device["Vendor"], (str, type(None))), (device["Language"], list),
                        (device["Fullname"], (str, type(None))),
                        (device["SchemaVersion"], (str, type(None))),(device["Warnings"], list),
                        (icon["DeviceType"], (str, type(None)))),(icon["Decorators"], (str, type(None))),\
                       (device["SysSwUpdatePrepare"], (str, type(None))),(device["SysSwUpdatePerform"], (str, type(None)))
            for i in key_data:
                if not isinstance(*i):
                    return False

    except KeyError as err_path:
        print("missing key")
        return False
    return True

print(validate_record_schema())
我想打印缺少的键(如果没有提供键)和响应为“false”的键

请根据这个修改我的脚本

Json数据

original_data =[{'Id': '12', 'Type': 'DevicePropertyChangedEvent', 'Payload': [{'DeviceType': 'producttype', 'DeviceId': 2, 'IsFast': False, 'Payload': {'DeviceInstanceId': 2, 'IsResetNeeded': False, 'ProductType': 'product'
    , 'Product': {'Family': 'home'}, 'Device': {'DeviceFirmwareUpdate': {'DeviceUpdateStatus': None, 'DeviceUpdateInProgress': None, 'DeviceUpdateProgress': None, 'LastDeviceUpdateId': None}, 'ManualAdded': False,
     'Name': {'Value': 'Jigital60asew', 'IsUnique': True}, 'State': None, 'Location': '', 'Serial': None, 'Version': '2.0.1.100','Vendor':'Sennheiser','Language':['en_GB']}}}]}]

我建议使用JSON模式来验证JSON,而不是重新发明轮子


听起来你好像在检查字典是否有键。你应该试试看。