Python金字塔解析json

2024-10-02 14:30:25 发布

您现在位置:Python中文网/ 问答频道 /正文

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

post请求如下所示:

$.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"
}

但是在服务器端,当我打印的时候我会收到这个(请求.正文)在

^{pr2}$

如何才能将发布的内容解析为JSON?金字塔什么时候该去request.json_主体是否包含已解析的json?在


Tags: name服务器sendjsonlocalhosthttpurltype
3条回答

请尝试在发送数据之前将其显式序列化为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"
}

我没有完美的答案,但我可以告诉你,这与编码有关。结构编码()或者u'str。你可以朝这个方向看。在

数据对象是字符串。它应该只是一个物体。删除引号

data: {"results": [{"robot_name": "Satikas", "result": null, "team_nr": 30, "team_name": "IT Vennad", "id": 57}]},

相关问题 更多 >