嵌套 json 数组的设置值
setting values for nested json array
我有一个嵌套的 JSON 文档,我想在嵌入的 JSON 数组中设置一个特定值,
例如:-
{
"name":"Jack",
"Address":{
"secondaryAddress":[{"name":"JOHN's Address",
"street":"new ave",
"city":"Canada",
"mobile":123456789
},
{"name":"Selena's Address",
"street":"second ave",
"city":"Canada",
"mobile":987654321
},
{"name":"Jack's Address",
"street":"third ave",
"city":"Canada"
}],
"primaryAddress":{},
}
}
我想在手机号码为 987654321 的特定 secondaryAddress 对象中将手机号码从 987654321 更改为 456789123。
我在我的项目中使用 jsonpath 来获取/设置值
为了得到我会使用:-
$.Address.secondaryAddress[*].mobile
这将 return 一组手机号码,例如:-
[
123456789,
987654321
]
set 也类似,
但我不确定如何继续这种我想在数组中设置特定对象的场景。
我尝试使用它,但它仍然设置所有数组对象的值 :-
DocumentContext cxt = JsonPath.parse(jsonString);
cxt.set("$.Address.secondaryAddress[*].mobile",456789123,Criteria.where("$.Address.secondaryAddress[*].mobile").is("987654321");
请帮助。
提前致谢:)
$.Address.secondaryAddress.[?(@.mobile=='987654321')]
上面的 jsonpath 查询会给你特定的 secondaryAddress 节点 mobile = 987654321
使用下面的表达式设置新的移动值-
$.Address.secondaryAddress.[?(@.mobile=='987654321')].mobile
我有一个嵌套的 JSON 文档,我想在嵌入的 JSON 数组中设置一个特定值,
例如:-
{
"name":"Jack",
"Address":{
"secondaryAddress":[{"name":"JOHN's Address",
"street":"new ave",
"city":"Canada",
"mobile":123456789
},
{"name":"Selena's Address",
"street":"second ave",
"city":"Canada",
"mobile":987654321
},
{"name":"Jack's Address",
"street":"third ave",
"city":"Canada"
}],
"primaryAddress":{},
}
}
我想在手机号码为 987654321 的特定 secondaryAddress 对象中将手机号码从 987654321 更改为 456789123。
我在我的项目中使用 jsonpath 来获取/设置值 为了得到我会使用:-
$.Address.secondaryAddress[*].mobile
这将 return 一组手机号码,例如:-
[
123456789,
987654321
]
set 也类似,
但我不确定如何继续这种我想在数组中设置特定对象的场景。
我尝试使用它,但它仍然设置所有数组对象的值 :-
DocumentContext cxt = JsonPath.parse(jsonString);
cxt.set("$.Address.secondaryAddress[*].mobile",456789123,Criteria.where("$.Address.secondaryAddress[*].mobile").is("987654321");
请帮助。
提前致谢:)
$.Address.secondaryAddress.[?(@.mobile=='987654321')]
上面的 jsonpath 查询会给你特定的 secondaryAddress 节点 mobile = 987654321 使用下面的表达式设置新的移动值-
$.Address.secondaryAddress.[?(@.mobile=='987654321')].mobile