【发布时间】:2020-05-08 00:36:24
【问题描述】:
我有一个这样的 json 对象:
{
"content" : [
{
"id" : 54
"foo" : "bar"
},
{
"id" : 43
"foo" : "bar"
},
{
"id" : 76
"foo" : "bar"
}
]
}
如果我想将多个项目添加到内容数组(顺序无关紧要),我可以使用带有单行/操作的 json 补丁添加到它吗?
{ "op": "add", "path": "/content/-", "value": [
{
"id" : 34
"foo" : "bar"
},
{
"id" : 23
"foo" : "bar"
},
{
"id" : 87
"foo" : "bar"
}
]
}
或者我是否必须为每个要添加的对象添加一行?
编辑:要清楚我想追加,而不是替换内容。
【问题讨论】:
-
我感觉你不确定你想做什么。为什么不:``` { "op":"add","path":{"content":[]}} 或 {"op":"add","path":{"content": {"values ": []}}} ```
-
不会删除存储在那里的现有项目吗?需要明确的是,我想追加而不是替换。
标签: arrays json rest http json-patch