-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy2json.py
More file actions
55 lines (41 loc) · 1.25 KB
/
py2json.py
File metadata and controls
55 lines (41 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# coding=utf-8
import json
__author__ = 'sinlov'
class Py2Json:
"""
for python2 json utils
use as
from tools.py2_json import Py2Json
Py2Json.dict_json_beauty(dict)
"""
def __init__(self):
pass
@staticmethod
def dict_json_encoding_utf_8(json_dict=dict):
# type: (dict)->str
"""
let python2 Json format utf-8
:param json_dict: for format dict
:return: json str
"""
return json.dumps(json_dict, encoding='utf-8', ensure_ascii=False)
@staticmethod
def dict_json_beauty(json_dict=dict, encode='utf-8'):
# type: (dict, str)->str
"""
let python2 Json format more right
:param json_dict: for format dict
:param encode: default is utf-8
:return: json str
"""
return json.dumps(json_dict, encoding=encode, ensure_ascii=False, indent=4)
@staticmethod
def dict_json_print_beauty(json_dict=dict, encode='utf-8'):
# type: (dict, str)->None
"""
print json with utf-8 beauty
:param json_dict: for print dict
:param encode: default is utf-8
:return: None
"""
print(json.dumps(json_dict, encoding=encode, ensure_ascii=False, indent=4))