如何将Postman正文中带有嵌套数组字段的原始JSON转换为表单数据?

问题描述 投票:0回答:1

昨天我问了这个question,但没有回应,也许是因为它与Django REST框架过于具体有关。我觉得这只是我用来发布的表单数据中的键值对问题。因此,我将以简化的内容重新提出这个问题。此原始JSON的表单数据格式等效于什么:

"markets": [
        {
            "market": 1,
            "name": "White Stone",
            "slabs": [
                1,
                2
            ],
            "thicknesses": [
                1,
                2,
                3
            ],
            "finish_types": [
                1
            ]
        },
        {
            "market": 2,
            "name": "White Marble",
            "slabs": [
                1
            ],
            "thicknesses": [
                1
            ],
            "finish_types": [
                1,
                3,
                6
            ]
        }
]

我想用Product字段创建一个新的markets实例。 markets是一个数组,具有自己的属性。其中一些也是数组。我在一个slabs中不能同时发送多个thicknessesfinish_typesmarketsslabsthicknessesfinish_types是外键。enter image description here当我尝试像上图那样进行键-值对时,唯一保存的元素是最后输入的元素。这是创建的markets

"markets": [
            {
                "id": 65,
                "market": 1,
                "name": "White Stone",
                "slabs": [
                    2
                ],
                "thicknesses": [
                    3
                ],
                "finish_types": [
                    1
                ]
            }
]

enter image description here当我尝试其他这样的密钥格式时,不会保存slabsthicknesses

"markets": [
            {
                "id": 66,
                "market": 1,
                "name": "White Stone",
                "slabs": [],
                "thicknesses": [],
                "finish_types": [
                    1
                ]
            }
]
json rest post django-rest-framework
1个回答
0
投票

根据this

这个怎么样:

Key                       Value

markets[0][id]             65
markets[0][market]         1
markets[0][name]           white stone
markets[0][slabs][]        2
markets[0][thicknesses][]  3
markets[0][finish_types][] 1
© www.soinside.com 2019 - 2024. All rights reserved.