当前位置: 首页>>代码示例>>Python>>正文


Python simplejson.JSONEncoder方法代码示例

本文整理汇总了Python中simplejson.JSONEncoder方法的典型用法代码示例。如果您正苦于以下问题:Python simplejson.JSONEncoder方法的具体用法?Python simplejson.JSONEncoder怎么用?Python simplejson.JSONEncoder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在simplejson的用法示例。


在下文中一共展示了simplejson.JSONEncoder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import JSONEncoder [as 别名]
def __init__(self, list_domain, list_key, list_name, list_description,
                 zk_hosts, aws_keyfile, s3_bucket, s3_endpoint="s3.amazonaws.com",
                 encoder_cls=json.JSONEncoder, decoder_cls=json.JSONDecoder,
                 update_callback=None, force_config_update=None):

        kwargs = {}
        if force_config_update is not None:
            kwargs['force_config_update'] = force_config_update

        super(ManagedJsonSerializableDataConfig, self).__init__(
            list_domain, list_key, list_name, list_description, zk_hosts,
            aws_keyfile, s3_bucket, s3_endpoint=s3_endpoint, **kwargs)

        self.encoder_cls = encoder_cls
        self.decoder_cls = decoder_cls
        self.update_callback = None
        if update_callback:
            self.set_update_callback(update_callback) 
开发者ID:pinterest,项目名称:kingpin,代码行数:20,代码来源:managed_datastructures.py

示例2: __init__

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import JSONEncoder [as 别名]
def __init__(self):
    json.JSONEncoder.__init__(self,
                              separators=(",", ":"),
                              ensure_ascii=False) 
开发者ID:google,项目名称:compare-codecs,代码行数:6,代码来源:gviz_api.py

示例3: test_encoding1

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import JSONEncoder [as 别名]
def test_encoding1(self):
        encoder = json.JSONEncoder(encoding='utf-8')
        u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
        s = u.encode('utf-8')
        ju = encoder.encode(u)
        js = encoder.encode(s)
        self.assertEqual(ju, js) 
开发者ID:gkudos,项目名称:qgis-cartodb,代码行数:9,代码来源:test_unicode.py

示例4: default

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import JSONEncoder [as 别名]
def default(self, o):
        if o is JSONTestObject:
            if self.recurse:
                return [JSONTestObject]
            else:
                return 'JSONTestObject'
        return json.JSONEncoder.default(o) 
开发者ID:gkudos,项目名称:qgis-cartodb,代码行数:9,代码来源:test_recursion.py

示例5: test_encoding1

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import JSONEncoder [as 别名]
def test_encoding1(self):
        encoder = json.JSONEncoder(encoding='utf-8')
        u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
        s = u.encode('utf-8')
        ju = encoder.encode(u)
        js = encoder.encode(s)
        self.assertEquals(ju, js) 
开发者ID:linuxscout,项目名称:mishkal,代码行数:9,代码来源:test_unicode.py

示例6: default

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import JSONEncoder [as 别名]
def default(self, obj):
        if hasattr(obj, 'to_dict'):
            return maybe_call(obj.to_dict)
        elif hasattr(obj, 'to_list'):
            return maybe_call(obj.to_list)
        elif isinstance(obj, types.GeneratorType):
            return list(obj)
        return super(JSONEncoder, self).default(obj) 
开发者ID:awslabs,项目名称:lambda-chef-node-cleanup,代码行数:10,代码来源:json.py

示例7: __init__

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import JSONEncoder [as 别名]
def __init__(self):
    super(JSONEncoder, self).__init__(ensure_ascii=False, encoding="utf-8")
    self._registry = {} 
开发者ID:kdart,项目名称:pycopia,代码行数:5,代码来源:json.py

示例8: default

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import JSONEncoder [as 别名]
def default(self, obj):
    for checker, simplifier in self._registry.itervalues():
      if checker(obj):
        return simplifier(obj)
    return super(JSONEncoder, self).default(obj)

#  def encode(self, obj):
#    for checker, simplifier in self._registry.itervalues():
#      if checker(obj):
#        return super(JSONEncoder, self).encode(simplifier(obj))
#    return super(JSONEncoder, self).encode(obj) 
开发者ID:kdart,项目名称:pycopia,代码行数:13,代码来源:json.py

示例9: GetJSONEncoder

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import JSONEncoder [as 别名]
def GetJSONEncoder():
    # encoding: native -> JSON
  global _ENCODER
  if _ENCODER is None:
    _ENCODER = JSONEncoder()
    _ENCODER.register("datetime", _DtChecker, _DtSimplifier)
    _ENCODER.register("date", _DateChecker, _DateSimplifier)
    _ENCODER.register("set", _set_checker, _set_simplifier)
    _ENCODER.register("enums", _enum_checker, _enum_simplifier)
  return _ENCODER 
开发者ID:kdart,项目名称:pycopia,代码行数:12,代码来源:json.py

示例10: process_json_request

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import JSONEncoder [as 别名]
def process_json_request(self, method, args = None):
        try:
            return self.doprocess_json_request(method, args=args)
        except:
            print_exc()
            return json.JSONEncoder().encode({'success': 'false'}) 
开发者ID:alesnav,项目名称:p2ptv-pi,代码行数:8,代码来源:WebUI.py

示例11: encode

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import JSONEncoder [as 别名]
def encode(self, obj):
        if isinstance(obj, float):
            return format(obj, '.6f')
        return json.JSONEncoder.encode(self, obj) 
开发者ID:cc0411,项目名称:devops,代码行数:6,代码来源:interactive.py

示例12: default

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import JSONEncoder [as 别名]
def default(self, obj):
        try:
            return default_json_serializer(obj)
        except TypeError:
            pass
        return json.JSONEncoder.default(self, obj) 
开发者ID:accelero-cloud,项目名称:appkernel,代码行数:8,代码来源:engine.py

示例13: default

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import JSONEncoder [as 别名]
def default(self, obj):
    if isinstance(obj, (np.float_, np.float32, np.float16, np.float64)):
      return float(obj)
    elif isinstance(obj,
                    (np.intc, np.intp, np.int_, np.int8, np.int16, np.int32,
                     np.int64, np.uint8, np.uint16, np.uint32, np.uint64)):
      return int(obj)
    elif isinstance(obj, np.ndarray):
      obj = obj.tolist()
    return json.JSONEncoder.default(self, obj) 
开发者ID:google-research,项目名称:disentanglement_lib,代码行数:12,代码来源:results.py

示例14: default

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import JSONEncoder [as 别名]
def default(self, obj):
        if isinstance(obj, DottedCollection):
            return obj.store
        else:
            return json.JSONEncoder.default(obj) 
开发者ID:DavexPro,项目名称:PocHunter,代码行数:7,代码来源:dotted.py

示例15: default

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import JSONEncoder [as 别名]
def default(self, obj):
        """Encode an object from the types supported."""
        if isinstance(obj, tuple(TYPES.values())):
            key = '__%s__' % obj.__class__.__name__
            return {key: obj.__dict__}
        return json.JSONEncoder.default(self, obj) 
开发者ID:PanDAWMS,项目名称:pilot,代码行数:8,代码来源:CustomEncoder.py


注:本文中的simplejson.JSONEncoder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。