gpt4 book ai didi

json - 需要一些 JSON Schema 的清晰度

转载 作者:行者123 更新时间:2023-12-05 01:24:31 25 4
gpt4 key购买 nike

假设我的表结构如下所示:

tblPhoneNumber
+-------------------+----------------------+
| Id | uniqueidentifier |
| Number | string |
| PhoneNumberTypeId | smallint |
+-------------------+----------------------+

tblPhoneNumberType
+-------------------+----------------------+
| Id | smallint |
| Type | string |
| Description | string |
+-------------------+----------------------+

我的类(class)是这样的:

public class PhoneNumber {
public Guid Id { get; set; }
public string Number { get; set; }
public PhoneNumberType PhoneNumberType { get; set; }
}

public class PhoneNumberType {
public short Id { get; set; }
public string Type { get; set; }
public string Description { get; set; }
}

我的问题是,以上内容的有效 JSON 模式是什么?我的最终目标是提供一个公共(public) api,同时能够使用 SQL 或 NoSql 存储库。所以我希望能够验证数据。

我最初的尝试如下:

电话号码.json

{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "PhoneNumber",
"type": "object",
"description": "A schema for a general phone number.",
"properties": {
"id": {
"type": "object",
"description": "A unique identifier."
},
"number": {
"type": "string",
"description": "The telephone number."
},
"phoneNumberType": { "$ref": "http://www.mywebsite.com/phoneNumberType#" },
},
"required": [
"id",
"number",
"phoneNumberType"
]
}

phoneNumberType.json

{
"id": "http://www.mywebsite.com/phoneNumberType#",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "PhoneNumberType",
"description": "A phone number type enum.",
"type": "object",
"properties": {
}
}

具体来说,我的问题是,在 phoneNumber.json 中,我是否正确引用了 phoneNumberType?如果没有,我该怎么做?

谢谢。

最佳答案

是的,您所写的内容 100% 符合标准。然而,不同的 JSON Schema 实现以不同的方式管理引用。通常需要一个额外的步骤来告诉图书馆您希望如何解析引用。您将需要查看您正在使用的特定实现的文档,以确定您可能遗漏了什么。

关于json - 需要一些 JSON Schema 的清晰度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36538350/

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