给定一个类似以下JSON对象:
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"book_id": "214515",
"title": "Sayings of the Century",
"price": 8.95,
"reviews": [
{
"rating": 2,
"reviewer": "Amazon",
"weight": 0
},
{
...
}
]
},
{
...
}
是否有可能选择书籍的book_id,以及该书籍的部分或全部评论?
结果可能类似于下面这样:
[
{
"book_id": "...",
"reviews": [
...
]
},
{
...
}
]
我一直在使用Jayway jsonpath:https://github.com/json-path/JsonPath
当处理数组(如“reviews”)并以编程方式进行连接时,以下内容不适用于解决方案:
List ids = JsonPath.read(json, "$.store.books[*].book_id");
List reviews = JsonPath.read(json, "$.store.books[*].reviews[*]");