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


Python json.JSONEncoder类代码示例

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


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

示例1: default

	def default(self, obj):
		if isinstance(obj, User):
			dic={'login':obj.login,'p':obj.p,'name':obj.name,'logged':obj.logged}
			return dic
		if isinstance(obj, Repository):
			dic={'org':obj.org,'name':obj.name,'directory':obj.directory,'json_exists':obj.json_exists,'exists':obj.exists,'content':obj.content,'file_name':obj.file_name}
			return dic
		else:
			JSONEncoder.default(self, obj)
开发者ID:SOM-Research,项目名称:graph-github,代码行数:9,代码来源:server.py

示例2: default

    def default(self, obj):
        if isinstance(obj, date):
            return dateutil.simple_format_date(obj)
        elif isinstance(obj, datetime):
            return dateutil.simple_format_datetime(obj)
        elif isinstance(obj, Iterable) and not isinstance(obj, (dict, list, set)):
            # 这个实现可能有问题
            return JSONEncoder.default(self, list(obj))

        return JSONEncoder.default(self, obj)
开发者ID:zheng-ji,项目名称:ToyCollection,代码行数:10,代码来源:wrappers.py

示例3: default

 def default(self, obj):
     from datatypes import User
     app.logger.debug("running custom jsonencoder")
     if isinstance(obj, User):
         # Implement code to convert Passport object to a dict
         user_dict = {"name": obj.displayName(), "userID": obj.userID, "isAdmin": obj.isAdmin,
                      "isMCRMember": obj.isMCRMember,
                      "isAssociateMember": obj.isAssociateMember, "isCRA": obj.isCRA,
                      "isCollegeBill": obj.isCollegeBill}
         return user_dict
     else:
         JSONEncoder.default(self, obj)
开发者ID:Clare-MCR,项目名称:MCRevents,代码行数:12,代码来源:mealbooker.py

示例4: default

 def default(self, obj):
     try:
         if isinstance(obj, date):
             return JSONEncoder.default(
                 self,
                 datetime(obj.year, obj.month, obj.day))
         iterable = iter(obj)
     except TypeError:
         pass
     else:
         return list(iterable)
     return JSONEncoder.default(self, obj)
开发者ID:danmilon,项目名称:fragofonias,代码行数:12,代码来源:app.py

示例5: default

 def default(self, obj):
     if isinstance(obj, ObjectId):
         return json_util.dumps(obj)
     elif isinstance(obj, datetime.datetime):
         return calendar.timegm(obj.utctimetuple())*1000
     else:
         return JSONEncoder.default(self, obj)
开发者ID:hydrosolutions,项目名称:international-rivers,代码行数:7,代码来源:encoder.py

示例6: default

    def default(self, obj):
        try:
            if isinstance(obj, datetime):
                if obj.utcoffset() is not None:
                    obj = obj - obj.utcoffset()
                millis = int(
                    calendar.timegm(obj.timetuple()) * 1000 +
                    obj.microsecond / 1000
                )
                return millis

            if isinstance(obj, sqlalchemy.orm.state.InstanceState):
                return ""

            if isinstance(obj, ScannerStatistic):
                return ""
            if isinstance(obj, ScannerLocation):
                return ""

            iterable = iter(obj)
        except TypeError:
            pass
        else:
            return list(iterable)
        return JSONEncoder.default(self, obj)
开发者ID:Ipukema,项目名称:PokeStats,代码行数:25,代码来源:Map.py

示例7: default

 def default(self, o):
     if isinstance(o, PersistentID):
         return o.hex
     elif isinstance(o, Enum):
         return o.name
     else:
         return FlaskJSONEncoder.default(self, o)
开发者ID:roguePanda,项目名称:itunes-remote,代码行数:7,代码来源:json.py

示例8: default

 def default(self, obj):
     try:
         if isinstance(obj, datetime):
             return serialize_datatime(obj)
     except TypeError:
         pass
     return JSONEncoder.default(self, obj)
开发者ID:mapix,项目名称:Maruko,代码行数:7,代码来源:serialization.py

示例9: default

 def default(self, obj):
     if isinstance(obj, Character):
         return obj.__dict__
     elif isinstance(obj, Weapon):
         return obj.__dict__
     else:
         return JSONEncoder.default(self, obj)
开发者ID:Onewaysidewalks,项目名称:runestory_assistant,代码行数:7,代码来源:models.py

示例10: default

    def default(self, obj):
        try:
            if isinstance(obj, datetime):
                if obj.utcoffset() is not None:
                    obj = obj - obj.utcoffset()
                millis = int(
                        calendar.timegm(obj.timetuple()) * 1000 +
                        obj.microsecond / 1000
                )
                return millis

            if isinstance(obj, date):
                millis = int(
                        calendar.timegm(obj.timetuple()) * 1000

                )
                return millis

            if isinstance(obj, np.int64):
                val = int(obj)
                return val
            iterable = iter(obj)
        except TypeError:
            pass
        else:
            return list(iterable)
        return JSONEncoder.default(self, obj)
开发者ID:sharmaudi,项目名称:myrepo,代码行数:27,代码来源:app.py

示例11: default

 def default(self, o):
     if isinstance(o, Segment):
         return {
             'id': o.id,
             'text_id': o.text_id,
             'slug': o.slug,
             'content': xml_transform(o.content),
         }
     elif isinstance(o, Text):
         return {
             'id': o.id,
             'name': o.name,
             'slug': o.slug,
             'xmlid_prefix': o.xmlid_prefix
         }
     elif isinstance(o, Card):
         return {
             'primary': self.default(o.primary),
             'translations': [self.default(x) for x in o.translations],
             'commentaries': [self.default(x) for x in o.commentaries],
         }
     elif isinstance(o, ChildCard):
         return {
             'text_id': o.text_id,
             'segments': [self.default(x) for x in o.segments],
         }
     return JSONEncoder.default(self, o)
开发者ID:sanskrit,项目名称:learnsanskrit.org,代码行数:27,代码来源:lso_json_encoder.py

示例12: default

 def default(self, obj):
     if isinstance(obj, datetime):
         if obj.utcoffset() is not None:
             obj = obj - obj.utcoffset()
         return str(obj)
     else:
         return JSONEncoder.default(self, obj)
开发者ID:MITRECND,项目名称:multiscanner,代码行数:7,代码来源:api.py

示例13: default

    def default(self, o):  # pylint: disable=method-hidden
        """Convert unserializable types for JSON encoding."""
        if isinstance(o, datetime):
            # Stuffr uses ISO dates
            return o.isoformat()

        return JSONEncoder.default(self, o)
开发者ID:BitLooter,项目名称:Stuffr-backend,代码行数:7,代码来源:__init__.py

示例14: default

 def default(self, obj):
     if hasattr(obj, '__getitem__') and hasattr(obj, 'keys'):
         return dict(obj)
     if isinstance(obj, datetime.datetime):
         return obj.strftime('%Y-%m-%d %H:%M:%S')
     if isinstance(obj, ObjectId):
         return str(obj)
     return _JSONEncoder.default(self, obj)
开发者ID:PyFansLi,项目名称:chiki,代码行数:8,代码来源:_flask.py

示例15: default

 def default(self, o):
     if isinstance(o, datetime.date):
         if isinstance(o, datetime.datetime):
             return str(o.replace(microsecond=0))
         return str(o)
     if hasattr(o, 'as_dict'):
         return o.as_dict()
     return JSONEncoder.default(self, o)
开发者ID:oceanobservatories,项目名称:ooi-status,代码行数:8,代码来源:__init__.py


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