[英]JSON patch rfc6902: Sequential operation and index
在JSON补丁中,如何在同一个数组上使用索引进行后续操作。 例如,考虑一下
var source = { colors: ['Red', 'Green', 'Blue'] };
var target = { colors: [] };
补丁文档(操作)
[{"op":"remove","path":"/colors/0"},
{"op":"remove","path":"/colors/1"},
{"op":"remove","path":"/colors/2"}]
如果我考虑源的索引,上面的索引是正确的。 当我按顺序应用它时,索引不正确。 也就是说,如果我删除第0个和第1个索引,则索引2处没有元素。
我可以想到几种方法来处理这个问题。 对数组进行所有删除操作的组,然后在删除期间保留一个临时结构来保存/操作索引中的更改。 或者,保持索引相对于变异值
[{"op":"remove","path":"/colors/0"},
{"op":"remove","path":"/colors/0"},
{"op":"remove","path":"/colors/0"}]
如果操作被认为是顺序资源的变异,那么这是有意义的。
对此有什么标准吗?
Evaluation of a JSON Patch document begins against a target JSON
document. Operations are applied sequentially in the order they
appear in the array. Each operation in the sequence is applied to
the target document; the resulting document becomes the target of the
next operation.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.