Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rest 如何在python中解析未知键的json_Rest_Flask Restful - Fatal编程技术网

Rest 如何在python中解析未知键的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

我正在使用PythonFlask框架来处理RESTAPI调用。带有查询字符串的rest调用将以JSON格式存储,代码如下。现在查询字符串中的参数根据各种过滤器是动态的,当所有键都未知时,我们如何动态解析此数组

@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数据