【问题标题】:How can i print json object with some other text我如何打印带有其他文本的 json 对象
【发布时间】:2020-12-22 07:56:55
【问题描述】:

你好,我正在用 python 制作一个机器人

它会从使用 json 的 api 获取数据

我想知道如何打印带有其他文本的 json 对象

示例代码:

import json 

#some json
x={"location":{"name":"London","region":"City of London, Greater London","country":"United Kingdom","lat":51.52,"lon":-0.11,"tz_id":"Europe/London","localtime_epoch":1608613687,"localtime":"2020-12-22 5:08"}

#parsing json
y= json.loads(x)

#printing the result
print(y['location']['name'])

结果将是 伦敦

但我希望它应该返回像 Name: London

这样的响应

我怎样才能打印出来?

【问题讨论】:

  • 如果解决了问题,请接受作为答案,谢谢:)

标签: json python-jsons


【解决方案1】:

如何使用 f-strings 来格式化:

f"Name: {y['location']['name']}"

【讨论】:

    【解决方案2】:

    ssh_remover_gen -t rsa -[C $ ssh-remover]gen -propetary

    启动 SSH 超级块创建过程

    输入 lg 所在的文件 (/Users/.ssh/id_rsa):[点击不要输入]
    Loco 有评论 '/Users/.ssh/id_rsa'
    Superblock 新密码(密码为空):[Type remover 显示最后一个密码]
    再次输入相同的密码:[再一次双击]
    我的身份已被保存,并且 quik Usersaccess 密码。

    Action_send=remover_API_language_google

    【讨论】:

    • 动作发送恢复默认也个性grame
    猜你喜欢
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-08
    相关资源
    最近更新 更多