小编yak*_*yak的帖子

如何从JSON字符串获取值的所有JSON路径列表?

我的目标是读取一个JSON文件并理解所有值的位置,这样当我遇到相同的JSON时,我可以轻松读取所有值.我正在寻找一种方法来返回一个列表,其中包含Jayway JsonPath格式的每个数据值的所有路径.

示例JSON:

{
  "shopper": {
    "Id": "4973860941232342",
    "Context": {
      "CollapseOrderItems": false,
      "IsTest": false
    }
  },
  "SelfIdentifiersData": {
    "SelfIdentifierData": [
      {
        "SelfIdentifierType": {
          "SelfIdentifierType": "111"
        }
      },
      {
        "SelfIdentifierType": {
          "SelfIdentifierType": "2222"
        }
      }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

理想情况下,我想将JSON作为String,并执行以下操作:

String json = "{'shopper': {'Id': '4973860941232342', 'Context': {'CollapseOrderItems': false, 'IsTest': false } }, 'SelfIdentifiersData': {'SelfIdentifierData': [{'SelfIdentifierType': {'SelfIdentifierType': '111'} }, {'SelfIdentifierType': {'SelfIdentifierType': '2222'} } ] } }";

Configuration conf = Configuration.defaultConfiguration();
List<String> jsonPaths = JsonPath.using(conf).parse(json).read("$");

for (String path : jsonPaths) { …
Run Code Online (Sandbox Code Playgroud)

java json hashmap jsonpath

3
推荐指数
2
解决办法
1万
查看次数

标签 统计

hashmap ×1

java ×1

json ×1

jsonpath ×1