gpt4 book ai didi

python - 如何将 Python POST 数据转换为 JSON?

转载 作者:太空宇宙 更新时间:2023-11-04 03:41:35 26 4
gpt4 key购买 nike

我在 Python 中有以下代码:

def post(self):
example = self.request.get("example")
other = self.request.get("other")

如果未知,如何获取所有发布数据?我是 Python 的新手,但大致是这样的:

def post(self):
array = self.request.get()
myJSON = MagicArrayToJson(array)
self.response.headers['Content-Type'] = 'application/json'
self.response.write(myJSON)

最佳答案

这可能取决于您使用的框架。但我想它们都有非常相同的符号,例如 self.request.dataself.request.body 用于发布请求。

像这样尝试self.request.data

def post(self):
data = self.request.data

# If data is in querystring, convert it to dict
# urlparse lib is convenient for this

myJSON = MagicArrayToJson(array)
self.response.headers['Content-Type'] = 'application/json'
self.response.write(myJSON)

关于python - 如何将 Python POST 数据转换为 JSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26190829/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com