gpt4 book ai didi

php - Django , python : Is there a simple way to convert PHP-style bracketed POST keys to multidimensional dict?

转载 作者:可可西里 更新时间:2023-11-01 16:27:29 24 4
gpt4 key购买 nike

具体来说,我有一个调用 Django 服务的表单(使用 Piston 编写,但我认为这不相关),通过 POST 发送如下内容:

edu_type[3][name] => a
edu_type[3][spec] => b
edu_type[3][start_year] => c
edu_type[3][end_year] => d
edu_type[4][0][name] => Cisco
edu_type[4][0][spec] => CCNA
edu_type[4][0][start_year] => 2002
edu_type[4][0][end_year] => 2003
edu_type[4][1][name] => fiju
edu_type[4][1][spec] => briju
edu_type[4][1][start_year] => 1234
edu_type[4][1][end_year] => 5678

我想在 Python 端处理这个得到这样的东西:

edu_type = {
'3' : { 'name' : 'a', 'spec' : 'b', 'start_year' : 'c', end_year : 'd' },
'4' : {
'0' : { 'name' : 'Cisco', 'spec' : 'CCNA', 'start_year' : '2002', 'end_year' : '2003' },
'1' : { 'name' : 'fiju', 'spec' : 'briju', 'start_year' : '1234', 'end_year' : '5678' },
},
}

有什么想法吗?谢谢!

最佳答案

我用 python 做了一个小解析器来处理多维字典,你可以在 https://github.com/bernii/querystring-parser 找到它。

关于php - Django , python : Is there a simple way to convert PHP-style bracketed POST keys to multidimensional dict?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1890013/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com