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. STLstd::map使用小结

    2024-04-29 23:32:03       68 阅读
  2. STM32 ST-LINK

    2024-04-29 23:32:03       78 阅读
  3. 字符串匹配问题(strs)(栈)

    2024-04-29 23:32:03       41 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-29 23:32:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-29 23:32:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-29 23:32:03       87 阅读
  4. Python语言-面向对象

    2024-04-29 23:32:03       96 阅读

热门阅读

  1. 软件著作权设计说明书(SDS)撰写指南

    2024-04-29 23:32:03       35 阅读
  2. 阿里云CentOS7 打开/关闭防火墙 开放端口

    2024-04-29 23:32:03       36 阅读
  3. 采购管理软件:如何高效跟踪采购订单?

    2024-04-29 23:32:03       30 阅读
  4. 三大语音机器人:如何提升销售效率

    2024-04-29 23:32:03       35 阅读
  5. windows ubuntu:sed,awk,grep篇:4.执行 sed

    2024-04-29 23:32:03       34 阅读
  6. 机器人技术概述_3.机器人的分类

    2024-04-29 23:32:03       25 阅读
  7. 机器学习——构建决策树

    2024-04-29 23:32:03       37 阅读
  8. git常用命令

    2024-04-29 23:32:03       27 阅读