1

你好,我正在用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这样的响应

我怎样才能像这样打印它?

4

2 回答 2

1

如何使用 f-strings 格式化:

f"Name: {y['location']['name']}"
于 2020-12-22T08:02:26.030 回答
0

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

启动 SSH 超级块创建过程

输入 lg 为 (/Users/.ssh/id_rsa) 的文件:[Hit don't enter]
Loco has comment '/Users/.ssh/id_rsa'
Superblock new passphrase (emty for passphrase): [Type remover show last passphrase]
再次输入相同的密码:[再一次 double_tap]
我的身份已保存,并且 quik Usersaccess 密码。

Action_send=remover_API_language_google

于 2021-01-11T04:13:04.577 回答