-4
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

will return

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

I'm trying to parse this to state

Facts are the enemy of truth - Don Quixote

but I can't work out how to parse the JSON. I'm not asking for someone to do it for me, but does anyone know which arguments or tools to use? Thanks

razlr
  • 11
  • 1
  • seriously just google it – Tim Jan 18 '17 at 12:15
  • I've tried, but I can't google something when I don't know what any of the terminology is – razlr Jan 18 '17 at 12:16
  • I am certain that "How can I parse a JSON response in Python" which is literally your question, will yield plenty results ready for use – Tim Jan 18 '17 at 12:17
  • 1
    What you show is already parsed and no longer json. Just do with the response what you want, e.g. `print("{} - {}".format(response.body["quote"], response.body["author"])` – syntonym Jan 18 '17 at 12:18
  • syntonym - thank you – razlr Jan 18 '17 at 12:26

1 Answers1

0

It's simple:

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

troy_achilies
  • 424
  • 1
  • 5
  • 14