Aestate
JSON.py
Go to the documentation of this file.
1 __version__ = '1.0.0'
2 __all__ = [
3  'Json'
4 ]
5 
6 __author__ = 'CACode <cacode@163.com>'
7 
8 from . import _default_encoder, JSONEncoder, _default_decoder, JSONDecoder
9 from decimal import Decimal
10 
11 
12 class Json:
13 
14  @staticmethod
15  def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
16  allow_nan=True, cls=None, indent=None, separators=None,
17  encoding='utf-8', default=None, use_decimal=True,
18  namedtuple_as_object=True, tuple_as_array=True,
19  bigint_as_string=False, sort_keys=False, item_sort_key=None,
20  for_json=False, ignore_nan=False, int_as_string_bitcount=None,
21  iterable_as_array=False, **kw):
22  """
23  转json字符串
24  """
25  if (not skipkeys and ensure_ascii and
26  check_circular and allow_nan and
27  cls is None and indent is None and separators is None and
28  encoding == 'utf-8' and default is None and use_decimal
29  and namedtuple_as_object and tuple_as_array and not iterable_as_array
30  and not bigint_as_string and not sort_keys
31  and not item_sort_key and not for_json
32  and not ignore_nan and int_as_string_bitcount is None
33  and not kw
34  ):
35  return _default_encoder.encode(obj)
36  if cls is None:
37  cls = JSONEncoder
38  return cls(
39  skipkeys=skipkeys, ensure_ascii=ensure_ascii,
40  check_circular=check_circular, allow_nan=allow_nan, indent=indent,
41  separators=separators, encoding=encoding, default=default,
42  use_decimal=use_decimal,
43  namedtuple_as_object=namedtuple_as_object,
44  tuple_as_array=tuple_as_array,
45  iterable_as_array=iterable_as_array,
46  bigint_as_string=bigint_as_string,
47  sort_keys=sort_keys,
48  item_sort_key=item_sort_key,
49  for_json=for_json,
50  ignore_nan=ignore_nan,
51  int_as_string_bitcount=int_as_string_bitcount,
52  **kw).encode(obj)
53 
54  @staticmethod
55  def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,
56  parse_int=None, parse_constant=None, object_pairs_hook=None,
57  use_decimal=False, **kw):
58  """
59  json转字典
60  """
61  if (cls is None and encoding is None and object_hook is None and
62  parse_int is None and parse_float is None and
63  parse_constant is None and object_pairs_hook is None
64  and not use_decimal and not kw):
65  return _default_decoder.decode(s)
66  if cls is None:
67  cls = JSONDecoder
68  if object_hook is not None:
69  kw['object_hook'] = object_hook
70  if object_pairs_hook is not None:
71  kw['object_pairs_hook'] = object_pairs_hook
72  if parse_float is not None:
73  kw['parse_float'] = parse_float
74  if parse_int is not None:
75  kw['parse_int'] = parse_int
76  if parse_constant is not None:
77  kw['parse_constant'] = parse_constant
78  if use_decimal:
79  if parse_float is not None:
80  raise TypeError("use_decimal=True implies parse_float=Decimal")
81  kw['parse_float'] = Decimal
82  return cls(encoding=encoding, **kw).decode(s)
aestate.ajson.sim.JSON.Json.dumps
def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, encoding='utf-8', default=None, use_decimal=True, namedtuple_as_object=True, tuple_as_array=True, bigint_as_string=False, sort_keys=False, item_sort_key=None, for_json=False, ignore_nan=False, int_as_string_bitcount=None, iterable_as_array=False, **kw)
Definition: JSON.py:15
aestate.ajson.sim.JSON.Json.loads
def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, use_decimal=False, **kw)
Definition: JSON.py:55
aestate.ajson.sim.JSON.Json
Definition: JSON.py:12