json.dumps: dict ——> str

STEP1 :

https://bibfx.flyhsystem.com/datax/api/manage/reportDataPreview?dashBoardReportId=0fef1a97-fac6-4bb9-ac52-e352c88130fc&where={"conditions":[{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,'%Y-%m-%d %H:%m:%s')","isEXPR":true},"operator":">=","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"'2024-04-16 00:00:00'","isEXPR":true},"command":"AND"},{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,'%Y-%m-%d %H:%m:%s')","isEXPR":true},"operator":"<","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"'2024-04-17 00:00:00'","isEXPR":true},"command":"AND"}]}

STEP2 : 参数提取,给我全部整成斜杠了,我去

url = "https://bibfx.flyhsystem.com/datax/api/manage/reportDataPreview"
params = {
    "dashBoardReportId": "0fef1a97-fac6-4bb9-ac52-e352c88130fc",
    "where": "{\"conditions\":[{\"field\":{\"db\":\"bibfx_tms\",\"table\":\"bibfxuseronline_new\",\"name\":\"date_format(trace,'%Y-%m-%d %H:%m:%s')\",\"isEXPR\":true},\"operator\":\">=\",\"value\":{\"db\":\"bibfx_tms\",\"table\":\"bibfxuseronline_new\",\"name\":\"'2024-04-16 00:00:00'\",\"isEXPR\":true},\"command\":\"AND\"},{\"field\":{\"db\":\"bibfx_tms\",\"table\":\"bibfxuseronline_new\",\"name\":\"date_format(trace,'%Y-%m-%d %H:%m:%s')\",\"isEXPR\":true},\"operator\":\"<\",\"value\":{\"db\":\"bibfx_tms\",\"table\":\"bibfxuseronline_new\",\"name\":\"'2024-04-17 00:00:00'\",\"isEXPR\":true},\"command\":\"AND\"}]}"
}

type(params["where"])
str

params["where"] # 可以看到为JSON字符串
'{"conditions":[{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,\'%Y-%m-%d %H:%m:%s\')","isEXPR":true},"operator":">=","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"\'2024-04-16 00:00:00\'","isEXPR":true},"command":"AND"},{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,\'%Y-%m-%d %H:%m:%s\')","isEXPR":true},"operator":"<","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"\'2024-04-17 00:00:00\'","isEXPR":true},"command":"AND"}]}'

STEP3 : 构建时间变量参数

错误示范


begin_time = '2024-04-01 00:00:00'
end_time = '2024-04-02 00:00:00'

url = "https://bibfx.flyhsystem.com/datax/api/manage/reportDataPreview"
params = {
    "dashBoardReportId": "0fef1a97-fac6-4bb9-ac52-e352c88130fc",
    "where": "{\"conditions\":[{\"field\":{\"db\":\"bibfx_tms\",\"table\":\"bibfxuseronline_new\",\"name\":\"date_format(trace,'%Y-%m-%d %H:%m:%s')\",\"isEXPR\":true},\"operator\":\">=\",\"value\":{\"db\":\"bibfx_tms\",\"table\":\"bibfxuseronline_new\",\"name\":f\"'{begin_time}'\",\"isEXPR\":true},\"command\":\"AND\"},{\"field\":{\"db\":\"bibfx_tms\",\"table\":\"bibfxuseronline_new\",\"name\":\"date_format(trace,'%Y-%m-%d %H:%m:%s')\",\"isEXPR\":true},\"operator\":\"<\",\"value\":{\"db\":\"bibfx_tms\",\"table\":\"bibfxuseronline_new\",\"name\":f\"'{end_time}'\",\"isEXPR\":true},\"command\":\"AND\"}]}"
}

params["where"]  # begin_time、end_time变量未生效

'{"conditions":[{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,\'%Y-%m-%d %H:%m:%s\')","isEXPR":true},"operator":">=","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"\'{begin_time}\'","isEXPR":true},"command":"AND"},{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,\'%Y-%m-%d %H:%m:%s\')","isEXPR":true},"operator":"<","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"\'{end_time}\'","isEXPR":true},"command":"AND"}]}'

STEP4 : 正确示范

# 将STEP2的基础上打印下来
# 关键一步:

params["where"]
'{"conditions":[{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,\'%Y-%m-%d %H:%m:%s\')","isEXPR":true},"operator":">=","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"\'{begin_time}\'","isEXPR":true},"command":"AND"},{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,\'%Y-%m-%d %H:%m:%s\')","isEXPR":true},"operator":"<","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"\'{end_time}\'","isEXPR":true},"command":"AND"}]}'


# 敲黑板,

# 1 .JSON字符串要打印下来
print(params["where"])
{"conditions":[{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,'%Y-%m-%d %H:%m:%s')","isEXPR":true},"operator":">=","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"'{begin_time}'","isEXPR":true},"command":"AND"},{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,'%Y-%m-%d %H:%m:%s')","isEXPR":true},"operator":"<","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"'{end_time}'","isEXPR":true},"command":"AND"}]}

# 2. 再复制出来构建日期参数 ()

begin_time = '2024-04-01 00:00:00'
end_time = '2024-04-02 00:00:00'

url = "https://bibfx.flyhsystem.com/datax/api/manage/reportDataPreview"
params = {
    "dashBoardReportId": "0fef1a97-fac6-4bb9-ac52-e352c88130fc",
    "where":{"conditions":[{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,'%Y-%m-%d %H:%m:%s')","isEXPR":True},"operator":">=","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"'{begin_time}'","isEXPR":True},"command":"AND"},{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,'%Y-%m-%d %H:%m:%s')","isEXPR":True},"operator":"<","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"'{end_time}'","isEXPR":True},"command":"AND"}]}
}


type(params["where"])
dict

params # 字典
{'dashBoardReportId': '0fef1a97-fac6-4bb9-ac52-e352c88130fc',
 'where': {'conditions': [{'field': {'db': 'bibfx_tms',
     'table': 'bibfxuseronline_new',
     'name': "date_format(trace,'%Y-%m-%d %H:%m:%s')",
     'isEXPR': True},
    'operator': '>=',
    'value': {'db': 'bibfx_tms',
     'table': 'bibfxuseronline_new',
     'name': "'2024-04-01 00:00:00'",
     'isEXPR': True},
    'command': 'AND'},
   {'field': {'db': 'bibfx_tms',
     'table': 'bibfxuseronline_new',
     'name': "date_format(trace,'%Y-%m-%d %H:%m:%s')",
     'isEXPR': True},
    'operator': '<',
    'value': {'db': 'bibfx_tms',
     'table': 'bibfxuseronline_new',
     'name': "'2024-04-02 00:00:00'",
     'isEXPR': True},
    'command': 'AND'}]}}

STEP4 : dict --> str

begin_time = '2024-04-01 00:00:00'
end_time = '2024-04-12 00:00:00'

url = "https://bibfx.flyhsystem.com/datax/api/manage/reportDataPreview"
params = {
    "dashBoardReportId": "0fef1a97-fac6-4bb9-ac52-e352c88130fc",
    "where":json.dumps({"conditions":[{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,'%Y-%m-%d %H:%m:%s')","isEXPR":True},"operator":">=","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"'{begin_time}'","isEXPR":True},"command":"AND"},{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,'%Y-%m-%d %H:%m:%s')","isEXPR":True},"operator":"<","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"'{end_time}'","isEXPR":True},"command":"AND"}]})
}

type(params["where"])
str

params
{'dashBoardReportId': '0fef1a97-fac6-4bb9-ac52-e352c88130fc',
 'where': '{"conditions": [{"field": {"db": "bibfx_tms", "table": "bibfxuseronline_new", "name": "date_format(trace,\'%Y-%m-%d %H:%m:%s\')", "isEXPR": true}, "operator": ">=", "value": {"db": "bibfx_tms", "table": "bibfxuseronline_new", "name": "\'2024-04-01 00:00:00\'", "isEXPR": true}, "command": "AND"}, {"field": {"db": "bibfx_tms", "table": "bibfxuseronline_new", "name": "date_format(trace,\'%Y-%m-%d %H:%m:%s\')", "isEXPR": true}, "operator": "<", "value": {"db": "bibfx_tms", "table": "bibfxuseronline_new", "name": "\'2024-04-12 00:00:00\'", "isEXPR": true}, "command": "AND"}]}'}

#搞定 

或者:
在这里插入图片描述
在这里插入图片描述

可视化效果:



url = "https://bibfx.flyhsystem.com/datax/api/manage/reportDataPreview"

begin_time = '2024-04-15 00:00:00'
end_time = '2024-04-18 00:00:00'

params = {
    "dashBoardReportId": "0fef1a97-fac6-4bb9-ac52-e352c88130fc",
    "where": json.dumps({
        "conditions": [
            {
                "field": {
                    "db": "bibfx_tms",
                    "table": "bibfxuseronline_new",
                    "name": f"date_format(trace,'%Y-%m-%d %H:%m:%s')",
                    "isEXPR": True
                },
                "operator": ">=",
                "value": {
                    "db": "bibfx_tms",
                    "table": "bibfxuseronline_new",
                    "name": f"'{begin_time}'",
                    "isEXPR": True
                },
                "command": "AND"
            },
            {
                "field": {
                    "db": "bibfx_tms",
                    "table": "bibfxuseronline_new",
                    "name": f"date_format(trace,'%Y-%m-%d %H:%m:%s')",
                    "isEXPR": True
                },
                "operator": "<",
                "value": {
                    "db": "bibfx_tms",
                    "table": "bibfxuseronline_new",
                    "name": f"'{end_time}'",
                    "isEXPR": True
                },
                "command": "AND"
            }
        ]
    })
}

# 成功

params["where"]
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值