众所周知,Django=3 支持JSONField。我正在尝试使用 JavaScript 在我的 Django 项目中保存 JSON 数据,我在输入字段中获取数据,如下所示:
[{"id":1,"Name":"Antenna","Pieces":"","Weight":"","Weight Types":"","Quantity":"12",
"Cargo Charge":"12","Customs Charge":"12"},
{"id":2,"Name":"Soap","Pieces":"12","Weight":"12","Weight Types":"","Quantity":"",
"Cargo Charge":"12","Customs Charge":"12"}]
从输入字段中,我使用.
product_list = self.request.POST['product_list_json']
因此,product_list_json
是 inout 字段的名称。但是保存的数据被赋予了不同的视图,保存的数据看起来像:
"[{\"id\":1,\"Name\":\"Antenna\",\"Pieces\":\"\",\"Weight\":\"\",\"Weight Types\":\"\",
\"Quantity\":\"12\",\"Cargo Charge\":\"12\",\"Customs Charge\":\"12\"},
{\"id\":2,\"Name\":\"Soap\",\"Pieces\":\"12\",\"Weight\":\"12\",\"Weight Types\":\"\",
\"Quantity\":\"\",\"Cargo Charge\":\"12\",\"Customs Charge\":\"12\"}]"
问题是,数据是用额外的“\”保存的。我能做些什么来解决这个问题?