Azure 逻辑应用程序,解析 JSON,但可能为空

Azure Logic App, parse JSON, but possible null

我想解析 json,基于以下 类:

public class DerModel
{
    public string Name { get; set; }
    public string Email { get; set; }
}

public class DriverPositiveResultModel
{
    public int DriverId { get; set; }
    public string DriverName { get; set; }
    public string DriverSSN { get; set; }
    public string CarrierName { get; set; }
    public DerModel DER { get; set; }
}

和以下架构:

{
    "properties": {
        "CarrierName": {
            "type": "string"
        },
        "DER": {
            "properties": {
                "Email": {
                    "type": "string"
                },
                "Name": {
                    "type": "string"
            }
        },
        "type": "object"
    },
    "DriverId": {
        "type": "integer"
    },
    "DriverName": {
        "type": "string"
    },
    "DriverSSN": {
        "type": "string"
    }
},
"type": "object"

}

但逻辑允许,DER 可以为空。如何在架构中设置它?

需要指定可以为空:

"type": ["object","null"]

因此您的代码将如下所示:

{
    "properties": {
        "CarrierName": {
            "type": "string"
        },
        "DER": {
            "properties": {
                "Email": {
                    "type": "string"
                },
                "Name": {
                    "type": "string"
            }
        },
        "type": ["object","null"]
    },
    "DriverId": {
        "type": "integer"
    },
    "DriverName": {
        "type": "string"
    },
    "DriverSSN": {
        "type": "string"
    }
},
"type": "object"
}