匹配记录的定义:当至少三个字段的值为M00或M01时,一个RecordMatch对象。
如何使用Jayway JsonPath计算限定为匹配记录的JsonPath对象的数量?我们可以使用Java代码进行计算,但需要在项目中使用JsonPath表达式进行计算。
{
"Inquiry": {
"Matches": [
{
"TotalLength": 8,
"TerminatedRecord": [
{
"RecordMatch": {
"Name": "M01",
"AsName": "M02",
"Address": "M01",
"PhoneNumber": "M00",
"AltPhoneNumber": "M00",
"CountrySubdivisionTaxId": "M00",
"NationalId": "M00",
"Country": "M00",
"DBA": "M00",
"PrincipalMatch": [
{
"Name": "M01",
"Address": "M01",
"PhoneNumber": "M01",
"AltPhoneNumber": "M00",
"NationalId": "M01",
"DriversLicense": "M01"
}
]
}
},
{
"RecordMatch": {
"Name": "M01",
"AsName": "M02",
"Address": "M01",
"PhoneNumber": "M00",
"AltPhoneNumber": "M00",
"CountrySubdivisionTaxId": "M00",
"NationalId": "M00",
"Country": "M00",
"DBA": "M00",
"PrincipalMatch": [
{
"Name": "M01",
"Address": "M01",
"PhoneNumber": "M01",
"AltPhoneNumber": "M00",
"NationalId": "M01",
"DriversLicense": "M01"
}
]
}
},
{
"RecordMatch": {
"Name": "M01",
"AsName": "M02",
"Address": "M01",
"PhoneNumber": "M00",
"AltPhoneNumber": "M00",
"CountrySubdivisionTaxId": "M00",
"NationalId": "M00",
"Country": "M00",
"DBA": "M00",
"PrincipalMatch": [
{
"Name": "M01",
"Address": "M01",
"PhoneNumber": "M01",
"AltPhoneNumber": "M00",
"NationalId": "M01",
"DriversLicense": "M01"
}
]
}
}
]
}
]
}
}发布于 2022-10-02 16:58:09
你可以考虑另一个图书馆乔森。
https://github.com/octomix/josson
反序列化
Josson josson = Josson.fromJsonString(
"{" +
" \"Inquiry\": {" +
" \"Matches\": [" +
" {" +
" \"TotalLength\": 8," +
" \"TerminatedRecord\": [" +
" {" +
" \"RecordMatch\": {" +
" \"Name\": \"M01\"," +
" \"AsName\": \"M02\"," +
" \"Address\": \"M01\"," +
" \"PhoneNumber\": \"M00\"," +
" \"AltPhoneNumber\": \"M00\"," +
" \"CountrySubdivisionTaxId\": \"M00\"," +
" \"NationalId\": \"M00\"," +
" \"Country\": \"M00\"," +
" \"DBA\": \"M00\"," +
" \"PrincipalMatch\": [" +
" {" +
" \"Name\": \"M01\"," +
" \"Address\": \"M01\"," +
" \"PhoneNumber\": \"M01\"," +
" \"AltPhoneNumber\": \"M00\"," +
" \"NationalId\": \"M01\"," +
" \"DriversLicense\": \"M01\"" +
" }" +
" ]" +
" }" +
" }," +
" {" +
" \"RecordMatch\": {" +
" \"Name\": \"M01\"," +
" \"AsName\": \"M02\"," +
" \"Address\": \"M01\"," +
" \"PhoneNumber\": \"M00\"," +
" \"AltPhoneNumber\": \"M00\"," +
" \"CountrySubdivisionTaxId\": \"M00\"," +
" \"NationalId\": \"M00\"," +
" \"Country\": \"M00\"," +
" \"DBA\": \"M00\"," +
" \"PrincipalMatch\": [" +
" {" +
" \"Name\": \"M01\"," +
" \"Address\": \"M01\"," +
" \"PhoneNumber\": \"M01\"," +
" \"AltPhoneNumber\": \"M00\"," +
" \"NationalId\": \"M01\"," +
" \"DriversLicense\": \"M01\"" +
" }" +
" ]" +
" }" +
" }," +
" {" +
" \"RecordMatch\": {" +
" \"Name\": \"M01\"," +
" \"AsName\": \"M02\"," +
" \"Address\": \"M01\"," +
" \"PhoneNumber\": \"M00\"," +
" \"AltPhoneNumber\": \"M00\"," +
" \"CountrySubdivisionTaxId\": \"M00\"," +
" \"NationalId\": \"M00\"," +
" \"Country\": \"M00\"," +
" \"DBA\": \"M00\"," +
" \"PrincipalMatch\": [" +
" {" +
" \"Name\": \"M01\"," +
" \"Address\": \"M01\"," +
" \"PhoneNumber\": \"M01\"," +
" \"AltPhoneNumber\": \"M00\"," +
" \"NationalId\": \"M01\"," +
" \"DriversLicense\": \"M01\"" +
" }" +
" ]" +
" }" +
" }" +
" ]" +
" }" +
" ]" +
" }" +
"}");查询
JsonNode node = josson.getNode(
"Inquiry" +
".Matches" +
".TerminatedRecord" +
".RecordMatch@" +
".flatten('_')" +
".toArray()" +
".[in('M00','M01')]*" +
".size()" +
".[? >= 3]" +
".@size()");
System.out.println(node.toPrettyString());输出
3https://stackoverflow.com/questions/42931289
复制相似问题