Rest 如何在python中解析未知键的json
我正在使用PythonFlask框架来处理RESTAPI调用。带有查询字符串的rest调用将以JSON格式存储,代码如下。现在查询字符串中的参数根据各种过滤器是动态的,当所有键都未知时,我们如何动态解析此数组Rest 如何在python中解析未知键的json,rest,flask-restful,Rest,Flask Restful,我正在使用PythonFlask框架来处理RESTAPI调用。带有查询字符串的rest调用将以JSON格式存储,代码如下。现在查询字符串中的参数根据各种过滤器是动态的,当所有键都未知时,我们如何动态解析此数组 @app.route("/results") def resultsInfo(): if request.method == 'GET': # copy app arguments data= request.args.copy() Json对象将在python
@app.route("/results")
def resultsInfo():
if request.method == 'GET':
# copy app arguments
data= request.args.copy()
Json对象将在python中转换为字典,所以如果Json数据未知,您可以通过字典方法获取键和值
body = request.get_json() # returns a dictionary
for key, value in body.items():
print(key, ' ', value) # this is how to see the all keys and values in dictionary(json sent by client)
你想对它做什么?因为它已经是一个字典,所以您不需要进一步解析它。这些值和键将用于过滤JSON数据