【问题标题】:How to append current date into existing JSON file?如何将当前日期附加到现有的 JSON 文件中?
【发布时间】:2021-12-18 12:45:47
【问题描述】:

我正在使用 vscode
我有以下格式的 JSON 文件

{
    "appointments": [
        {
            "date": "the date I want to add into",
            "time": "12pm"
        }
    ]
}

我想将日期添加到我的 JSON 文件中

预期:

{
    "appointments": [
        {
            "date": "4-11-2021",
            "time": "12pm"
        }
    ]
}

【问题讨论】:

  • 告诉我如何解决这个编码问题”是off-topic for Stack Overflow。我们希望你做出一个honest attempt at the solution,发布那个尝试,然后问一个关于它的具体问题(即解释为什么它没有'不工作或有什么问题)。
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: python json list date datetime


【解决方案1】:

首先是您给我们的简单字典。 其次,括号有问题。

这是您的意见:

temp = {
"appointments": [
    {
        "date": "the date I want to add into",
        "time": "12pm"
    }
]
}

temp = { "约会": [ { "date": "我要添加的日期", “时间”:“中午 12 点” } ] }

要得到你的结果,只需运行这个:

temp['appointments'][0]['date'] = "01/01/2021"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-25
    • 1970-01-01
    • 2021-08-26
    • 1970-01-01
    • 2018-11-17
    • 2023-03-19
    • 1970-01-01
    相关资源
    最近更新 更多