【问题标题】:Python Extract Value from JsonPython 从 Json 中提取值
【发布时间】:2017-07-09 12:17:15
【问题描述】:

我需要从 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'

我需要提取“情节”值

【问题讨论】:

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


    【解决方案1】:

    plotdata 内部:

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

    【讨论】:

      猜你喜欢
      • 2015-12-19
      • 2021-04-21
      • 2020-05-06
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 2014-09-13
      相关资源
      最近更新 更多