【发布时间】:2015-05-19 15:58:00
【问题描述】:
我有一个复杂的 JSON 结构。我不想排除一个部分并在两个桶中获取列表。说一个为“包含”,另一个为“排除”。 下面给出了示例 JSON。
{
"Item": {
"Items": [{
"Items": [{
"category": "fruit",
"Item": {
"Items": [{
"Text": "Apple"
},
{
"Text": "Orange"
},
{
"Text": "Grapes"
},
{
"Text": "Guava"
}],
"Types": ["Value",
"Value",
"Value",
"Value"]
},
"Type": "Or"
},
{
"category": "fruit",
"Item": {
"Text": "Pineapple"
},
"Type": "Value"
}],
"Types": ["Constraint",
"Constraint"]
},
{
"category": "fruit",
"Item": {
"Text": "Banana"
},
"Type": "Value"
}],
"Types": ["Not",
"Constraint"]
},
"Type": "And"}
这里我们有类别水果,其中 We Apple、Orange、Grapes 和 Guava 用“OR”表示,菠萝用“AND”表示,Banana 用“Not”表示。我试过一次
Item..Items[?(@.category='fruit')]..Text
它返回我
[ "Banana", "Apple", "Orange", "Grapes", "Guava", "Pineapple"]
但我希望 List 是
{["Apple", "Orange", "Grapes", "Guava", "Pineapple" ]
},{["Banana"]}
有没有办法在 JSON 路径中获得类似结构的东西
【问题讨论】:
-
一个 D3 巢可能是去这里的方式
标签: javascript json jsonpath