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

Ole*_* Sh 2 azure azure-logic-apps

我想根据以下类解析 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; }
}
Run Code Online (Sandbox Code Playgroud)

以及以下架构:

{
    "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"
Run Code Online (Sandbox Code Playgroud)

}

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

Car*_*cia 5

您需要指定它可以为空:

"type": ["object","null"]
Run Code Online (Sandbox Code Playgroud)

所以你的代码看起来像这样:

{
    "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"
}
Run Code Online (Sandbox Code Playgroud)