如何解析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
为无
答案 0 :(得分:1)
您必须先对其进行反序列化,然后才能对其进行查询。您正在使用的功能用于else entirely。使用stream
对象bounded或unbound上可用的Request
选项。
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)