如何在Python中解析JSON响应?这是全新的,我不知道使用哪些模块

时间:2017-01-18 12:14:43

标签: python json

import unirest
import json
response = unirest.post("https://andruxnet-random-famous-quotes.p.mashape.com/?cat=famous",
  headers={
    "X-Mashape-Key": "uukT9yvCgjmshXoCpkrCUNaZs3O0p1EwwkQjsnnudFw0VyeJVe",
    "Content-Type": "application/x-www-form-urlencoded",
    "Accept": "application/json"
  }
)
print response.body

将返回

{u'category': u'Famous', u'quote': u'Facts are the enemy of truth.', u'author': u"Don Quixote 'Man of La Mancha'"}

我试图将其解析为状态

Facts are the enemy of truth - Don Quixote

但我无法解决如何解析JSON的问题。我没有要求别人为我做,但有谁知道使用哪些论点或工具?感谢

1 个答案:

答案 0 :(得分:0)

很简单:

打印('%s - %s')%(response.body [' quote'],response.body [' author'] .split( "'")[0])

相关问题