Azure Logic应用程序,解析JSON,但可能为空 [英] Azure Logic App, parse JSON, but possible null

查看:0
本文介绍了Azure Logic应用程序,解析JSON,但可能为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想基于以下类解析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"
}

这篇关于Azure Logic应用程序,解析JSON,但可能为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆