From 09b3b42dc5f85c8f6ec56ac3c8476254ec6b3aee Mon Sep 17 00:00:00 2001 From: p34709852 Date: Mon, 10 Oct 2022 14:48:05 +0800 Subject: [PATCH] ADD file via upload --- c/test_dumps.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 c/test_dumps.py diff --git a/c/test_dumps.py b/c/test_dumps.py new file mode 100644 index 000000000..aab84d61d --- /dev/null +++ b/c/test_dumps.py @@ -0,0 +1,13 @@ +import json +data = { + 'name' : 'myname', + 'age' : 100, +} +# separators:是分隔符的意思,参数意思分别为不同dict项之间的分隔符和dict项内key和value之间的分隔符,把:和,后面的空格都除去了. +# dumps 将python对象字典转换为json字符串 +json_str = json.dumps(data, separators=(',', ':')) +print(type(json_str), json_str) + +# loads 将json字符串转化为python对象字典 +pyton_obj = json.loads(json_str) +print(type(pyton_obj), pyton_obj) \ No newline at end of file