【发布时间】:2018-01-26 05:17:19
【问题描述】:
假设我有这个 JSON 示例:
[
{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters":
{
"batter":
[
{ "id": "1001", "type": "Regular" },
{ "id": "1002", "type": "Chocolate" }
]
},
"topping":
[
{ "id": "5007", "type": "Powdered Sugar" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5003", "type": "Chocolate" },
{ "id": "5004", "type": "Maple" }
]
},
{
"id": "0002",
"type": "donut",
"name": "Raised",
"ppu": 0.55,
"batters":
{
"batter":
[
{ "id": "1005", "type": "DeleteMe" }
]
},
"topping":
[
{ "id": "5001", "type": "None" },
{ "id": "5002", "type": "Glazed" }
]
},
{
"id": "0003",
"type": "donut",
"name": "Old Fashioned",
"ppu": 0.55,
"batters":
{
"batter":
[
{ "id": "1001", "type": "Regular" },
{ "id": "1002", "type": "Chocolate" }
]
},
"topping":
[
{ "id": "5001", "type": "None" }
]
}
]
如何使用“DeleteMe”删除具有连击类型的整个元素?所以基本上,我希望删除整个元素 0002。我基本上想过滤掉所有带有batter type =“DeleteMe”的元素。
【问题讨论】:
-
第 1 步)解析 JSON。步骤 2) 改为询问 Ruby 数据结构。步骤 3) 从更新的数据结构生成 JSON。
标签: ruby-on-rails json ruby