Python 如何在Falcon中从POST请求读取原始json请求
如何解析JSON请求之类的内容Python 如何在Falcon中从POST请求读取原始json请求,python,falconframework,Python,Falconframework,如何解析JSON请求之类的内容 { "location_with_names": [ { "location_id": 101, "names": [ "a", "b", "c" ] }, { "location_id": 102, "names": [ "a", "e" ] }, { "l
{
"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)
带有_名称的位置_为无您必须先对其进行反序列化,然后才能查询它。你正在使用的那个函数是用来做某事的。使用
请求
对象上可用的流
选项,或
你试过这个吗?加载JSON字符串后,它只是dicts和list。什么是
req.get_param_as_list
?你得到的回复是什么样的?用于查询字符串参数
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)