【发布时间】:2016-05-24 10:47:58
【问题描述】:
在 JSON 负载中,如何从一个地方引用另一个地方的数据?
用例:想象一下定义良好的可序列化实体 A (a1, a2, a3) 和 B (b1, b2, b3)。现在考虑一个期望以下内容的 HTTP 请求负载:
{
data : {
"entityOne" : Entity Representation of entity A,
"entityTwo" : Entity Representation of entity B
},
relationships : {
"parenthood" : // Here I need to refer entityOne & entityTwo
// to express the notion of one being child of other
}
}
请告诉我您实现此引用的想法。
我考虑过的方法:
强制客户端针对有效负载中的每个实体发送一个临时参考 ID,并在关系中使用它们,如下所示
{
data : {
"entityOne" : { "id" : "temp1" -- other data for type A }
"entityTwo" : { "id" : "temp2" -- other data for type B }
},
relationships : {
"parenthood" : {
"parent" : "temp1",
"child" : "temp2"
}
}
}
【问题讨论】:
-
你已经想到的方法有什么问题?
-
强制客户端生成临时 ID 不是我想要的。想知道是否有标准的方式来引用 JSON 中的数据。我不确定,但 XPATH 允许在 XML 有效负载中使用类似的东西。已探索但找不到正确的指针
标签: json jsonschema object-reference object-relationships