gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 06:14:05 24 4
gpt4 key购买 nike

我想根据以下类解析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 逻辑应用程序,解析 JSON,但可能为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60662001/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com