【发布时间】:2021-05-13 07:37:03
【问题描述】:
如果我有一个这样的对象数组:
[
{
"remote" : [
{
"id" : 1
},
{
"id" : 2
},
{
" id" : 3
}
],
"text_id" : 1
},
{
"remote" : [
{
"id" : 4
},
{
"id" : 5
},
{
"id" : 6
}
],
"text_id" : 2
}
]
如何将“text_id”字段添加到 .[].remote[] 数组中的每个对象,使其变为
[
{
"remote" : [
{
"id" : 1,
"text_id" : 1
},
{
"id" : 2,
"text_id" : 1
},
{
" id" : 3,
"text_id" : 1
}
]
},
{
"remote" : [
{
"id" : 4,
"text_id" : 2
},
{
"id" : 5,
"text_id" : 2
},
{
"id" : 6,
"text_id" : 2
}
]
}
]
我已经花了几个小时试图弄清楚这一点。看起来必须有一种方法可以使用 foreach 指令来做到这一点,但是在我检查了手册之后,在我看来它很晦涩,所以我想也许有人可以举个例子。 谢谢。
【问题讨论】: