我的目标是读取一个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)