我使用python flask框架来处理rest API调用。带有查询字符串的rest调用将以JSON格式存储,查询字符串中的以下code.now参数根据不同的过滤器是动态的,当所有键都不知道时,我们如何动态解析这个数组?
@app.route("/results")
def resultsInfo():
if request.method == 'GET':
# copy app arguments
data= request.args.copy()
发布于 2017-03-02 18:15:01
Json对象会在python中转换成字典,所以如果json数据未知,可以通过字典方法获取key和value。
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)
https://stackoverflow.com/questions/42550749
复制相似问题