gpt4 book ai didi

Python Pyramid 解析 json

转载 作者:太空宇宙 更新时间:2023-11-04 10:20:11 25 4
gpt4 key购买 nike

我正在将 json 发布到 Python Pyramid 服务器,但我无法在服务器端解析它。

发布请求如下所示:

$.ajax({
url: "http://localhost:6543/linefollower/7/send_result",
type: "POST",
data: '{"results": [{"robot_name": "Satikas", "result": null, "team_nr": 30, "team_name": "IT Vennad", "id": 57}]}',
contentType: "application/json; charset=utf-8",
dataType: "json"
}

但是在服务器端,当我执行 print(request.body) 时,我收到了这个

b'%5B%7B%22robot_name%22%3A+%22Satikas%22%2C+%22result%22%3A+null%2C+%22team_nr%22%3A+30%2C+%22team_name%22%3A+%22IT+Vennad%22%2C+%22id%22%3A+57%7D%5D='

我应该怎么做才能将发布的内容解析为 JSON? Pyramid 的 request.json_body 什么时候应该包含解析后的 json?

最佳答案

尝试在发送之前将数据显式序列化为 JSON:

$.ajax({
url: "http://localhost:6543/linefollower/7/send_result",
type: "POST",
data: JSON.stringify({"results": [... "team_name": "IT Vennad", "id": 57}]}),
contentType: "application/json; charset=utf-8",
dataType: "json"
}

关于Python Pyramid 解析 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32725521/

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