From f26f7ca1e71a89779f9af820e02fac7cbfb54cde Mon Sep 17 00:00:00 2001 From: Bai Date: Mon, 15 Jun 2020 16:34:51 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9parsers=EF=BC=8C?= =?UTF-8?q?=E5=A4=84=E7=90=86dict=E5=AD=97=E6=AE=B5=E5=80=BC=EF=BC=9B?= =?UTF-8?q?=E8=A7=A3=E5=86=B3remote-app=20csv=E5=AF=BC=E5=85=A5=E6=97=B6?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/common/drf/parsers/csv.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/common/drf/parsers/csv.py b/apps/common/drf/parsers/csv.py index 254c73375..95a9ec732 100644 --- a/apps/common/drf/parsers/csv.py +++ b/apps/common/drf/parsers/csv.py @@ -58,6 +58,12 @@ class JMSCSVParser(BaseParser): col = col.replace("“", '"').replace("”", '"').\ replace("‘", '"').replace('’', '"').replace("'", '"') col = json.loads(col) + # 字典转换 + if isinstance(col, str) and col.find("{") != -1 and col.find("}") != -1: + # 替换中文格式引号 + col = col.replace("“", '"').replace("”", '"'). \ + replace("‘", '"').replace('’', '"').replace("'", '"') + col = json.loads(col) _row.append(col) return _row @@ -68,7 +74,7 @@ class JMSCSVParser(BaseParser): """ _row_data = {} for k, v in row_data.items(): - if isinstance(v, list) \ + if isinstance(v, list) or isinstance(v, dict)\ or isinstance(v, str) and k.strip() and v.strip(): _row_data[k] = v return _row_data