java 中值滤_java – JsonPath:按数组中的值过滤

我正在尝试使用Jsonpath在我的Json中按值过滤数组.我想在下面的

JSON中获取该国家的long_name.为了做到这一点,我按类型[0] ==“country”过滤adress_components但它似乎不起作用.

我试过的JsonPath:

$.results[0].address_components[?(@['types'][0]=="country")].long_name

我想要的结果是:“加拿大”.

JSON:

{

"results" : [

{

"address_components" : [

{

"long_name" : "5510-5520","short_name" : "5510-5520","types" : [ "street_number" ]

},{

"long_name" : "Yonge Street","short_name" : "Yonge St","types" : [ "route" ]

},{

"long_name" : "Willowdale","short_name" : "Willowdale","types" : [ "neighborhood","political" ]

},{

"long_name" : "North York","short_name" : "North York","types" : [ "political","sublocality","sublocality_level_1" ]

},{

"long_name" : "Toronto","short_name" : "Toronto","types" : [ "locality",{

"long_name" : "Toronto Division","short_name" : "Toronto Division","types" : [ "administrative_area_level_2",{

"long_name" : "Ontario","short_name" : "ON","types" : [ "administrative_area_level_1",{

"long_name" : "Canada","short_name" : "CA","types" : [ "country",{

"long_name" : "M2N 5S3","short_name" : "M2N 5S3","types" : [ "postal_code" ]

}

]

}

],"status" : "OK"

}

谢谢您的帮助.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值