假设我有一个这样的 json { "city" :[ "Bangalore", "Delhi", "Chennai", "Bangalore" ] } 现在我想做一个 json 路径查询来检查班加罗尔是否发生两次所以要检查我是否想提取班加罗尔进入数组的次数,那么我们如何构建 jsonpath 表达式?
I'm not sure I completely understand what you are asking but I guess you are using jayway's jsonpath library in java. In that case you can probably use this:
int amountOfBangalore = JsonPath.parse(json).read("$.city.[?(@ == \"Bangalore\")]").length();
Where you construct a list filled with each instance of 'bangalore' in the text and then call length() on that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.