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

标签 php python django http post

具体来说,我得到了一个调用 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/

相关文章:

python - 如何在 Pandas 中创建一个 mm-yyyy 列?

Django Grappelli 错误

javascript - 如何修复 Bootstrap 不破坏网格?

php - 通过 .htaccess 将额外的 get 变量附加到 URL

php - 如何使用 $_session[] 名称为 mysql 数据库定义表?

python - 尝试使用经度和纬度获取距离,但一直运行到错误 : 'Series' object has no attribute 'radians'

python - Google App Engine 上的 Django 在开发环境中使用 Cloud SQL

django - 设计基于 Django Rest Framework 角色的授权

PHP 比较登录详细信息

php - 在 PHP 代码中处理重音