Python中JSON对象的纯值

时间:2019-07-11 00:32:22

标签: python json

我坐下来尝试一些Python编程,我需要从JSON对象中获取数据。可以使用get_data方法完成此操作,但是随后我也获得了该名称,并且我只想要该值,怎么办?

代码看起来像这样

import json
from omdbapi.movie_search import GetMovie

movie = GetMovie(title='Interstellar', api_key='xxxxxx', plot='full')

Title = movie.get_data('Title')
Year = movie.get_data('Year')
print(Title)
print(Year)

我得到这个结果

======== RESTART: C:\Users\TELESHOP\Desktop\Johnny\Python\webtest1.py ========
{'Title': 'Interstellar'}
{'Year': '2014'}
>>> 

但是只想要这个

======== RESTART: C:\Users\TELESHOP\Desktop\Johnny\Python\webtest1.py ========
Interstellar
2014
>>> 

1 个答案:

答案 0 :(得分:1)

设为底部:

...
Title = movie.get_data('Title')['Title']
Year = movie.get_data('Year')['Year']
print(Title)
print(Year)

它将输出:

Interstellar
2014