2 回答

TA貢獻(xiàn)1779條經(jīng)驗(yàn) 獲得超6個(gè)贊
試試這個(gè): (.*"state":"CA".*"active":true.*)
演示:https : //regex101.com/r/hP6gS1/238
有用。
您可以根據(jù)需要更改標(biāo)簽名稱和值。它提取您所需的JSON內(nèi)容。

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊
Python版本
my_json = """[
{
"id": 1,
"last": "Doe",
"first": "John",
"location": {
"city": "Oakland",
"state": "CA",
"postalCode": "94607"
},
"active": true
}, {
"id": 2,
"last": "Doe",
"first": "Jane",
"location": {
"city": "San Francisco",
"state": "WA",
"postalCode": "94105"
},
"active": false
}, {
"id": 3,
"last": "Doe",
"first": "Jane",
"location": {
"city": "San Francisco",
"state": "CA",
"postalCode": "94105"
},
"active": true
}
]"""
import json
my_list = json.loads(my_json)
result_list = list(filter(
lambda d:
d["id"] == 1 or \
(d["location"]["state"] == "CA" and d["active"]),
my_list
))
添加回答
舉報(bào)