简体   繁体   中英

I don't know how to select specific items from json object in my web application using flask

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM