简体   繁体   English

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

[英]How to convert raw JSON with nested array field in Postman body into form-data?

Yesterday I've asked about this question but got no response maybe because it was too specific related to Django REST Framework.昨天我问过这个问题,但没有得到回应,可能是因为它与 Django REST Framework 的相关性太具体了。 I feel like it's simply the key-value pair problem in form-data I use to post.我觉得这只是我用来发布的表单数据中的键值对问题。 So I'm going to re-ask the question with simplified content.所以我将用简化的内容重新提问。
What is the form-data format's equivalent for this raw JSON:这个原始 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
            ]
        }
]

I want to create a new Product instance with markets field.我想用markets字段创建一个新的Product实例。 markets is an array and has its own attributes. markets是一个数组,有自己的属性。 Some of them are also arrays.其中一些也是数组。 I can't send more than 1 slabs , thicknesses , and finish_types each within a single markets .我不能在单个markets内分别发送 1 个以上的slabsthicknesses和完成finish_types slabs , thicknesses , and finish_types are foreign keys. slabsthicknessesfinish_types是外键。 在此处输入图片说明 When I tried to do the key-value pairs like the image above, the only saved elements are the last one inputed.当我尝试像上图那样进行键值对时,唯一保存的元素是最后一个输入的元素。
Here's the created markets :这是创建的markets

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

在此处输入图片说明 And when I tried another key format like this no slabs and thicknesses will be saved:当我尝试另一种像这样的键格式时,不会保存slabsthicknesses

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

According to this answer.根据这个答案。

How about you try this format:你试试这个格式怎么样:

Key                       Value

markets[0][market]         1
markets[0][name]           white stone
markets[0][slabs][]        2
markets[0][thicknesses][]  3
markets[0][finish_types][] 1

And maybe this Django thread might help you.也许这个Django 线程可能对你有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 邮递员:通过表单数据的嵌套 JSON 的 POST 请求不起作用(而通过原始数据可以) - Postman: POST request of nested JSON via form-data not working (while via raw-data ok) 如何在邮递员的同一请求中发送多部分/表单数据和嵌套的json? - How to send multipart/form-data and nested json in the same request in postman? 邮递员表单数据和 x-www-form-urlencoded 工作但原始 json 没有 - Postman form-data and x-www-form-urlencoded work but raw json doesn't 如何从Postman到Java获取Body原始JSON数据 - how to get Body raw JSON data from Postman to Java 如何使用 OpenAPI 3 在 multipart/form-data 请求的请求正文中格式化 JSON 数组? - How to format a JSON array in the request body of a multipart/form-data request with OpenAPI 3? 通过PostMan接收Json表单数据很困难 - Difficulty receiving Json Form-Data Through PostMan 如何将表单数据添加为 JMETER 正文 - How to add form-data as JMETER body 如何使用带有表单数据主体而不是json主体的http'POST'? (Angular2 /打字稿) - How to use http 'POST' with form-data body instead of json body? (Angular2/Typescript) 带有正文表单数据的邮递员请求到 json - Postman request with body Form data to json 邮递员原始数据有效,但表单数据不适用于节点中的 POST 请求 - Postman raw data works but form-data not works on POST request in node
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM