我可以期望在 MS Graph 中处理分页时,'nextLink' 将始终直接位于 json 对象响应中的集合之前吗?

Can I expect when handling pagination in MS Graph, that a 'nextLink' will always be directly before the collection in a json object response?

观看完 this page, I decided that I should start testing for server-side pagination by looking for @odata.nextLink fields in all my Graph API (v1.0) query responses, particularly on SharePoint resources. In the video at about 1:38s 上的 Microsoft 视频后,其中一位演示者表示 nextLink“通常”位于响应中的集合旁边。

到目前为止,这是我在分析查询的 json 响应时遇到的情况:集合字段紧跟在 json 中的 @odata.nextLink 字段之后目的。在下面的示例中,集合字段 'value' 紧跟在字段“@odata.nextLink”之后。

不过,我有点担心主持人的用词(“通常”)。 我可以期望使用 Graph API 时总是如此吗?

我想知道我是否可以构建我的查询算法,以便每当我遇到 nextLink 时,我都会查找下一个字段作为我将在访问 nextLink 字段时执行串联的集合,或者如果有些情况会破坏算法。

谢谢。

您永远不应在任何序列化响应中采用固定顺序。在 OData 的情况下,nextLink 将始终是顶级 属性 但 it can appear above or below 返回的集合:

All annotations or control information for a structural or navigation property MUST appear as a group immediately before the property itself. The one exception is the nextlink of a collection which MAY appear after the collection it annotates.

还值得注意的是,虽然其他注释始终出现在集合之前,但规范并未指定这些注释的顺序(idetag 等例外)。

使用 JSON 时,最好按名称检索属性(通常通过反序列化响应)。