【发布时间】:2021-08-23 01:19:33
【问题描述】:
我正在尝试编写一段代码,在其中过滤掉 Json 文件中的值 RSI, MOM, MOM_RSI 并按 Status 过滤。我想摆脱具有ACTIVE 的Status 的值,并摆脱状态为PAUSED 的值。我怎样才能做到这一点?
代码:
def reading():
with open('data.json') as f:
data = json.load(f)
return data
reading()
预期输出:
{
"RSI": [
{
"TradingPair": "BTCUSD",
"Status": "ACTIVE",
}
],
"MOM_RSI":[
{
"TradingPair": "BTCUSDT",
"Status": "ACTIVE",
}
]
}
JSON 文件:
{
"RSI": [
{
"TradingPair": "BTCUSD",
"Status": "ACTIVE",
}
],
"MOM":[
{
"TradingPair": "BCHUSDT",
"Status": "PAUSED",
}
],
"MOM_RSI":[
{
"TradingPair": "BTCUSDT",
"Status": "ACTIVE",
}
]
}
【问题讨论】:
标签: json python-3.x function dictionary format