首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用jayway查询json

如何使用jayway查询json
EN

Stack Overflow用户
提问于 2017-03-21 15:22:49
回答 1查看 109关注 0票数 1

匹配记录的定义:当至少三个字段的值为M00或M01时,一个RecordMatch对象。

如何使用Jayway JsonPath计算限定为匹配记录的JsonPath对象的数量?我们可以使用Java代码进行计算,但需要在项目中使用JsonPath表达式进行计算。

代码语言:javascript
运行
复制
{
  "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"
                }
              ]
            }
          }
        ]
      }
    ]
  }
}
EN

回答 1

Stack Overflow用户

发布于 2022-10-02 16:58:09

你可以考虑另一个图书馆乔森。

https://github.com/octomix/josson

反序列化

代码语言:javascript
运行
复制
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\"" +
    "                }" +
    "              ]" +
    "            }" +
    "          }" +
    "        ]" +
    "      }" +
    "    ]" +
    "  }" +
    "}");

查询

代码语言:javascript
运行
复制
JsonNode node = josson.getNode(
    "Inquiry" +
    ".Matches" +
    ".TerminatedRecord" +
    ".RecordMatch@" +
    ".flatten('_')" +
    ".toArray()" +
    ".[in('M00','M01')]*" +
    ".size()" +
    ".[? >= 3]" +
    ".@size()");
System.out.println(node.toPrettyString());

输出

代码语言:javascript
运行
复制
3
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42931289

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档