如何在AJAX中使用JSON API规格?

发布于 2025-02-02 17:27:12 字数 260 浏览 3 评论 0 原文

我的数据应该如何,以及如何使用AJAX使用JSON API规范来从端点获取数据。预先感谢

我的数据格式正确吗?

照片链接:

How should my data be and how can I use JSON API specification with ajax to fetch data from an endpoint. Thanks in advance

is the format of my data correct?

photo link:https://drive.google.com/file/d/1j6At0x3kX3wAQ178IBVG4tOHOMUrpxcw/view?usp=drivesdk

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

成熟的代价 2025-02-09 17:27:13

您评论中包含的屏幕截图中所示的数据格式不是有效的JSON:API文档。 JSON:API文档必须遵循

例如,您的屏幕截图中显示的JSON验证了规范的这一要求:

文件必须至少包含以下顶级成员之一:

  • 数据:该文档的“主要数据”
  • 错误:错误对象的数组
  • meta :一个包含非标准元信息的元对象。

https://jsonapi.org/format/#document-top-top-top-top-level


也代表资源的每个对象都违反了JSON:API规范的几个要求,例如:

资源对象必须至少包含以下顶级成员:

  • id
  • 类型

[...]

此外,资源对象可能包含这些顶级成员:

  • 属性:代表资源某些数据的属性对象。
  • 关系:描述资源与其他JSON之间关系的关系对象:API资源。
  • 链接:一个链接对象,其中包含与资源相关的链接。
  • meta :包含关于无法表示为属性或关系的资源的非标准元信息的元对象。

https://jsonapi.org/format/format/format/#ocument-resource-resource-bobjects-resource-objects


https://jsonapi.org/format/#document-resource-resource-objects JSON:API规范包含几个形式良好的JSON:API文档的示例。我建议您看看它们,以更好地理解规范。

The format of the data as shown in the screenshot included in your comment is not a valid JSON:API document. A JSON:API document must follow a specific schema as described in the JSON:API specification.

For example the JSON shown in your screenshot validates this requirement of the specification:

A document MUST contain at least one of the following top-level members:

  • data: the document’s “primary data”
  • errors: an array of error objects
  • meta: a meta object that contains non-standard meta-information.

https://jsonapi.org/format/#document-top-level

Also each object representing a resource violates several requirements of the JSON:API specification, for example:

A resource object MUST contain at least the following top-level members:

  • id
  • type

[...]

In addition, a resource object MAY contain any of these top-level members:

  • attributes: an attributes object representing some of the resource’s data.
  • relationships: a relationships object describing relationships between the resource and other JSON:API resources.
  • links: a links object containing links related to the resource.
  • meta: a meta object containing non-standard meta-information about a resource that can not be represented as an attribute or relationship.

https://jsonapi.org/format/#document-resource-objects

The JSON:API specification contains several examples of well-formed JSON:API documents. I would recommend to have a look at them to understand the specification better.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文