如何解析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)