本文整理匯總了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