简体   繁体   English

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

[英]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.

相关问题 我不知道如何在我的 web 应用程序中使用 Z319C34606A7D4A9767 - I don't know how to select specific items from jsonnified object in my web application using flask web 数据抓取问题我不知道如何从文件中导出信息。html 到我的 python 程序 - web scraping problem with data i don't know how to export information from file.html to my python programme 在我们不知道有多少嵌套对象具有相同键的情况下,如何遍历 json object 的特定键? - How can I loop over a specific key of a json object where we don't know how many nested objects have the same key? TypeError:TextIOWrapper 类型的 Object 不是 JSON 可序列化我不知道如何处理 - TypeError: Object of type TextIOWrapper is not JSON serializable I don't know how to handle this 我不知道如何在我的游戏中显示可供用户选择的课程列表? - I don't know how to show a list of classes for user to choose from in my game? 我不知道如何使我的匹配系统正常工作 - I don't know how to make my matching system work 从字符串中解析 XML 报告“垃圾”在我的文件中,我不知道如何找到它 - Parsing XML from string reports “junk” in my file, I don't know how to locate it Python:我的代码出错,我不知道如何修复它 - Python: Error in my code and i don't know how to fix it 我不知道如何将 .html 文件之一从测验应用程序连接到 django 应用程序。 (找不到页面 (404)) - I don't know how to connect one of the .html files from the quiz application to the django application. (Page not found (404)) 如何使用 Flask、GitHub 和 Heroku 将我的 Tensorflow 深度学习模型部署为 Web 应用程序 - How can I deploy my Tensorflow Deep Learning model as a web application using Flask, GitHub and Heroku
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM