-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsonformat.py
33 lines (30 loc) · 1.12 KB
/
jsonformat.py
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
class someutil:
def toJson(self,obj,strObj):
if type(obj)==list:
strObj+="["
for listV in obj:
if type(listV)==dict or type(listV)==list:
strObj+=self.toJson(listV, "")
strObj+=","
else:
strObj+=listV
strObj+=","
strObj+="]"
if type(obj)==dict:
strObj+="{"
for key in obj.keys():
if type(obj[key])==dict or type(obj[key])==list:
strObj+="\""+key+"\""+":"
strObj+=self.toJson(obj[key], "")
strObj+=","
else:
if type(key)==str:
strObj+="\""+key+"\""
strObj+=":"
if type(obj[key])==str:
strObj+="\""+obj[key]+"\""
else:
strObj+=str(obj[key])
strObj+=","
strObj+="}"
return strObj.replace(",}","}").replace(",]","]")