【发布时间】:2020-02-28 10:09:38
【问题描述】:
我目前正在构建一个 Telegram Bot 并在 Google Places API 上获取 JSON 响应,以将附近的位置返回给用户。 我得到的json响应如下:
results" : [
{
"name" : "Golden Village Tiong Bahru",
"opening_hours" : {
"open_now" : true
},
"rating" : 4.2,
"types" : [ "movie_theater", "point_of_interest", "establishment" ],
"user_ratings_total" : 773
},
{
"name" : "Cathay Cineplex Cineleisure Orchard",
"opening_hours" : {
"open_now" : true
},
"rating" : 4.2,
"types" : [ "movie_theater", "point_of_interest", "establishment" ],
"user_ratings_total" : 574
}
]
我当前获取字典中特定项目的代码
json.dumps([[s['name'], s['rating']] for s in object_json['results']], indent=3)
当前结果:
[
[
"Golden Village Tiong Bahru",
4.2
],
[
"Cathay Cineplex Cineleisure Orchard",
4.2
]
]
我想获得名称和评级并并排显示:
Golden Village Tiong Bahru : 4.2,
Cathay Cineplex Cineleisure Orchard : 4.2
请帮忙。
【问题讨论】:
-
for s in object_json['results']: print('%(name)s : %(rating)s' % s).
标签: python json python-telegram-bot