如何从Falcon中的Post请求中读取RAW JSON请求



如何解析JSON请求类似的内容?

{
  "location_with_names": [
    {
      "location_id": 101,
      "names": [
        "a",
        "b",
        "c"
      ]
    },
    {
      "location_id": 102,
      "names": [
        "a",
        "e"
      ]
    },
    {
      "location_id": 103,
      "names": [
        "f",
        "c"
      ]
    }
  ]
}

示例代码:

def on_post(self, req, resp):
    location_with_names = req.get_param_as_list('location_with_names')
    print(location_with_names)

location_with_names是无

您必须先对其进行审理,然后您可以查询它。您正在使用的功能完全适用于其他功能。使用Request对象上可用的stream选项,有限或取消结合。

import json
def on_post(self, req, resp):
    raw_data = json.load(req.bounded_stream)
    location_with_names = raw_data.get('location_with_names')
    print(location_with_names)

相关内容

  • 没有找到相关文章

最新更新