[英]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 个以上的slabs
、 thicknesses
和完成finish_types
。 slabs
, thicknesses
, and finish_types
are foreign keys. slabs
、 thicknesses
和finish_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:当我尝试另一种像这样的键格式时,不会保存
slabs
和thicknesses
:
"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.