[英]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我的 output
"abcdefg" “abcdefg”
what I want我想要的是
abcdefg abcdefg
How should I fix it?我应该如何解决它?
jsonify
builds a Flask Response object. jsonify
构建一个 Flask 响应 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.请注意,这里的
response_json
实际上是一个 python 数据结构(字典),因为这是response.json
返回的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.