本文整理汇总了Python中json.py方法的典型用法代码示例。如果您正苦于以下问题:Python json.py方法的具体用法?Python json.py怎么用?Python json.py使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json
的用法示例。
在下文中一共展示了json.py方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _encode
# 需要导入模块: import json [as 别名]
# 或者: from json import py [as 别名]
def _encode(data):
"""Adapted from Django source:
https://github.com/django/django/blob/master/django/core/serializers/json.py
"""
if isinstance(data, datetime.datetime):
r = data.isoformat()
if data.microsecond:
r = r[:23] + r[26:]
if r.endswith("+00:00"):
r = r[:-6] + "Z"
return r
elif isinstance(data, datetime.date):
return data.isoformat()
elif isinstance(data, datetime.time):
r = data.isoformat()
if data.microsecond:
r = r[:12]
return r
elif isinstance(data, datetime.timedelta):
return data.total_seconds()
elif isinstance(data, (decimal.Decimal, uuid.UUID)):
return compat.to_str(data)
示例2: dumps
# 需要导入模块: import json [as 别名]
# 或者: from json import py [as 别名]
def dumps(obj, **kwargs):
"""Escape characters."""
# https://github.com/mitsuhiko/flask/blob/master/flask/json.py
return json.dumps(obj, **kwargs) \
.replace(u'<', u'\\u003c') \
.replace(u'>', u'\\u003e') \
.replace(u'&', u'\\u0026') \
.replace(u"'", u'\\u0027')
示例3: tojson_filter
# 需要导入模块: import json [as 别名]
# 或者: from json import py [as 别名]
def tojson_filter(obj, **kwargs):
"""Filter for JSON output in templates."""
# https://github.com/mitsuhiko/flask/blob/master/flask/json.py
return Markup(dumps(obj, **kwargs))
示例4: json_text_
# 需要导入模块: import json [as 别名]
# 或者: from json import py [as 别名]
def json_text_():
"""Returns the parser for JSON Text"""
# Taken from https://github.com/vlasovskikh/funcparserlib/blob/master/funcparserlib/tests/json.py
# and modified slightly
unwrap = lambda x: x.value
null = (n('null') | n('Null')) >> const(None) >> unwrap
value = forward_decl()
member = (string >> unwrap) + op_(u':') + value >> tuple
object = (
op_(u'{') +
maybe(member + many(op_(u',') + member) + maybe(op_(','))) +
op_(u'}')
>> make_object)
array = (
op_(u'[') +
maybe(value + many(op_(u',') + value) + maybe(op_(','))) +
op_(u']')
>> make_array)
value.define(
null
| (true >> unwrap)
| (false >> unwrap)
| object
| array
| (number >> unwrap)
| (string >> unwrap))
return value