我不知道如何使用 Flask 在我的 Web 应用程序中 select 来自 json 对象的特定项目
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)
我的输出
“abcdefg”
我想要的
abcdefg
我该如何解决?
jsonify
构建 Flask Response 对象。使用此代码,您将尝试像访问字典一样访问它:
results = jsonify( response_json )["results"][0] # bad
我想你正在寻找:
results = jsonify( response_json["results"[0] )
注意这里的 response_json
实际上是一个 python 数据结构(字典)因为那是 response.json
returns.
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)
我的输出
“abcdefg”
我想要的
abcdefg
我该如何解决?
jsonify
构建 Flask Response 对象。使用此代码,您将尝试像访问字典一样访问它:
results = jsonify( response_json )["results"][0] # bad
我想你正在寻找:
results = jsonify( response_json["results"[0] )
注意这里的 response_json
实际上是一个 python 数据结构(字典)因为那是 response.json
returns.