python中通过用户输入将数据获取到json骨架中

发布于 2025-01-15 16:55:44 字数 580 浏览 4 评论 0原文

假设我有一个像这样的输入框架,

    "thing": {
        "name": "",
        "date": ""
    },
    "anotherThing": [
        {
            "name": "",
            "description": "",
            "expirationDate": ""
       
        }
    ],

我将如何通过用户输入填充空白,以便它看起来像这样?

    "thing": {
        "name": "Water",
        "date": "07/27/2022"
    },
    "anotherThing": [
        {
            "name": "Fire",
            "description": "is hot",
            "expirationDate": "05/22/2026"
       
        }
    ],

或者类似上面的内容取决于用户输入的内容?

Say I have an input skeleton like this

    "thing": {
        "name": "",
        "date": ""
    },
    "anotherThing": [
        {
            "name": "",
            "description": "",
            "expirationDate": ""
       
        }
    ],

How would I go about filling in the blanks through user inputs so it could look something like this?

    "thing": {
        "name": "Water",
        "date": "07/27/2022"
    },
    "anotherThing": [
        {
            "name": "Fire",
            "description": "is hot",
            "expirationDate": "05/22/2026"
       
        }
    ],

or something like that above depending on what the user inputs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无人问我粥可暖 2025-01-22 16:55:44

您需要将 JSON 写入文件


data = {
  'message': converted,

}
with open('data.json', 'w', encoding='utf-8') as f:
  json.dump(data, f, ensure_ascii=False, indent=4)


you would need to write the JSON as a file


data = {
  'message': converted,

}
with open('data.json', 'w', encoding='utf-8') as f:
  json.dump(data, f, ensure_ascii=False, indent=4)


~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文