使用JSONPath基于深度搜索的结果查找JSON对象

时间:2018-03-29 11:10:04

标签: java json jsonpath

我的JSON看起来如下所示。我想获得Attribute.Name / Attribute.content对,其中Name.Text [?(@。content ==' All-Inclusive Mgmt')]

我曾想过像

这样的东西
Attribute[?(@.Name.Text.content == 'All-Inclusive Mgmt']

可能有用..但是(我使用Java Jayway JSONPath)

时失败了

有人可以帮忙吗?这必须是纯JSONPath,如果可能的话

{
"Attribute":[
    {"Name":
{"Text":[
    {"content":"All-Inclusive Mgmt","Language":"ENG"},
    {"content":"??????","Language":"ZHT"}
]},
"Value":
{"Text":
 [{"content":"?","Language":"ZHT"},
  {"content":"Yes","Language":"ENG"},
  {"content":"Oui","Language":"FRE"},
  {"content":"Si","Language":"ITL"},
  {"content":"Si","Language":"SPN"},
  {"content":"Ja","Language":"GER"},
  {"content":"??","Language":"JPN"}
 ]
}
},
{"Name":
 {"Text":[
     {"content":"All-Inclusive Fees","Language":"ENG"},
     {"content":"??????","Language":"ZHT"}
 ]},
 "Value":
 {"Text":
  [{"content":"?","Language":"ZHT"},
   {"content":"Yes","Language":"ENG"},
   {"content":"Oui","Language":"FRE"},
   {"content":"Si","Language":"ITL"},
   {"content":"Si","Language":"SPN"},
   {"content":"Ja","Language":"GER"},
   {"content":"??","Language":"JPN"}
  ]
 }
}

]
}

2 个答案:

答案 0 :(得分:0)

此路径

$.Attribute[*].Name.Text[?(@.content=='All-Inclusive Mgmt')]

会给你

     { 
      "content":"All-Inclusive Mgmt",
      "Language":"ENG"
    }

这是具有值 All-Inclusive Mgmt

的内容

答案 1 :(得分:0)

我认为您必须按以下步骤逐步获取所需的内容:

代码段

int a = 5+myChar;

控制台输出

  

[{“ content”:“全包管理”,“ Language”:“ ENG”}]
  ENG
  [{“ content”:“ Yes”,“ Language”:“ ENG”},{“ content”:“ Yes”,“ Language”:“ ENG”}]

然后,您可以将结果进一步合并为一个对象。