简体   繁体   中英

Multidimensional arrays from a GET/POST request in Django

php array:

$post = [
  'contact' => [ // <--
      ['phone' => '1234', 'lname'=>'Anton'], 
      ['phone' => '123', 'lname'=>'Sima']
  ] // <--
];

or GET URL:

contact[][phone]=1234&contact[][lname]=Anton

How can I get data in this format using Django request ? I used https://github.com/bernii/querystring-parser , its result does not suit me, it deletes duplicate keys

PHP can't use duplicate keys, you need to add another array around them, if you want something like your example:

$post = [
    'contact' => [ // <--
        ['phone' => '1234', 'lname'=>'Anton'], 
        ['phone' => '123', 'lname'=>'Sima']
    ] // <--
];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM