尝试以下代码:

    1. import json
    2. jj = {
    3. "BC2204151940wx": {
    4. "状态": "排队中",
    5. "买家": " 张三",
    6. "备注": {
    7. "商品": "网络数据库SQL Server实验",
    8. "规格": "定制(送小实验1份)",
    9. "定价": 195,
    10. "实付": 99
    11. }
    12. }
    13. }
    14. id3 = '$BC2204151940wx'
    15. try:
    16. djj = re.findall(r'\$[A-Z][A-Z]\d{10}[a-z][a-z]',id3)[0].replace('$','')
    17. except IndexError:
    18. print('不是有效的订单号')
    19. if djj not in jj.keys():
    20. print('未查询到该订单记录\n可尝试通用查询,指令为 \'@订单查询\' 或者 \'@我的订单\'\n')
    21. idict = jj[djj]
    22. print(f"订单号:{djj}\n状态:{idict['状态']}\n备注:{json.dumps(idict['备注'],indent=4,ensure_ascii=False)}\n\n")
    23. print(f"订单号:{djj}\n状态:{idict['状态']}\n备注:{json.dumps(idict['备注'],indent=4,ensure_ascii=True)}\n\n")
    24. print(f"订单号:{djj}\n状态:{idict['状态']}\n备注:{json.dumps(idict['备注'],indent=4)}\n\n")

    image.png