Azure Logi c Приложение, анализ JSON, но возможно ноль - PullRequest
1 голос
/ 13 марта 2020

Я хочу проанализировать 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"

}

но logi c допускает, что DER может быть нулевым. Как установить это в схеме?

1 Ответ

3 голосов
/ 13 марта 2020

Вы должны указать, что оно может быть нулевым:

"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"
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...