我使用python 3,需要将请求uri参数转换为字典。
我的示例网址是:http://example.com/?item[test1]=foo&abc[0][6]=foo
在php中,从$_GET获取一个包含多维数组的字典,如下所示:
Array(
item => Array(
test1 => foo
),
abc => Array(
0 => Array(
6 => foo
)
)
)但是使用urlparse不能获得字典形式的数据:
>>> import urllib.parse as urlparse
>>> urlparse.parse_qs(urlparse.urlparse('http://example.com/?item[test1]=foo&abc[0][6]=foo').query)
{'item[test1]': ['foo'], 'abc[0][6]': ['foo']}将item[test1]作为单个参数获取。
如何获取多维字典?
发布于 2019-06-05 23:37:54
也许你可以在这里查看:https://github.com/bernii/querystring-parser,parser.py (https://github.com/bernii/querystring-parser/blob/master/querystring_parser/parser.py)应该能满足你的需求
https://stackoverflow.com/questions/56463631
复制相似问题