You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
355 B
22 lines
355 B
5 years ago
|
#!/usr/bin/python
|
||
|
# -*- coding: UTF-8 -*-
|
||
|
|
||
|
import json
|
||
|
|
||
|
|
||
|
def to_json_string(obj):
|
||
|
"""将对象转换成json字符串
|
||
|
|
||
|
:param obj: 对象
|
||
|
:type obj: object
|
||
|
|
||
|
:return: 返回json
|
||
|
:rtype: str
|
||
|
"""
|
||
|
if isinstance(obj, dict):
|
||
|
param = obj
|
||
|
else:
|
||
|
param = obj.__dict__
|
||
|
return json.dumps(param, ensure_ascii=False)
|
||
|
|