我想根据以下类解析 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"
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)