-1
response = requests.get(url)
response_json = response.json()
results = response_json['a'][0]
output = results['a_1'] + results['a_2'] + results['a_3']
return jsonify(output)

my output
"abcdefg"

what I want
abcdefg

How should I fix it?

1 Answers1

0

jsonify builds a Flask Response object. With this code you're trying to access it as if it was a dictionary:

results = jsonify( response_json )["results"][0]  # bad

I think you're looking for:

results  = jsonify( response_json["results"[0] )

Note that here response_json is actually a python datastructure (a dictionary) because that's what response.json returns.

v25
  • 7,096
  • 2
  • 20
  • 36
  • Thank you v25 now I can return the address, but now I have another problem. I return the address like "somewhere" but I want it as somewhere, I mean without double quotation. How should I do ? – 西山功一 Dec 10 '20 at 16:14
  • @西山功一 I suggest logging another question for this, to keep each question tidy. Please give a good sample of your code, actual output and excepted output. See [minimal reproducable example](https://stackoverflow.com/help/minimal-reproducible-example). – v25 Dec 10 '20 at 16:21
  • @西山功一 If you're returning json then `"abcdefg"` is a valid json, `abcdefg` is not. You're question doesn't metion how the frontend is loading this. Really the frontend should deal with the display part. Perhaps you should be investigating the `render_template` function to display something user-friendly in the browser. This is hard to answer without the extra info. – v25 Dec 11 '20 at 09:41
  • Okay I'm new to programming so I don't exactly know what 'how the frontend is loading this' mean, but I'm creating a web app using heroku and when I open the web application I want to return the output without "". I mean to display output without "". – 西山功一 Dec 11 '20 at 14:42