forked from p15670423/monkey
Update test_dumps03.py
This commit is contained in:
parent
628d21c68b
commit
59e5daecd8
|
@ -1,13 +1 @@
|
||||||
import json
|
print('1111')
|
||||||
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)
|
|
Loading…
Reference in New Issue