来自Json的Python提取值

时间:2017-07-09 12:17:15

标签: json python-3.x api get request

我需要从Json响应中获得精确值

Json回复:

{
"data": {
"plot": "Rudy has always been told that he was too small to play college football. But he is determined to overcome the odds and fulfill his dream of playing for Notre Dame.",
"name": "Rudy",
"rating": "7.5",
"genre": "Biography,Drama,Sport",
"poster_url": "https://images-na.ssl-images-amazon.com/images/M/MV5BZGUzMDU1YmQtMzBkOS00MTNmLTg5ZDQtZjY5Njk4Njk2MmRlXkEyXkFqcGdeQXVyNjc1NTYyMjg@._V1_UY268_CR5,0,182,268_AL_.jpg" 
     }
}

Python代码:

response = requests.get(
    "http://theapache64.xyz:8080/movie_db/search?keyword=Titanic")
json_data = json.loads(response.text)

print(json_data["plot"])

错误:

KeyError: 'plot'

我需要提取" plot"价值

1 个答案:

答案 0 :(得分:2)

plot位于data内:

print(json_data['data']['plot'])