types.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:PythonTelegram 作者: YongJang 项目源码 文件源码
def check_json(json_type):
        """
        Checks whether json_type is a dict or a string. If it is already a dict, it is returned as-is.
        If it is not, it is converted to a dict by means of json.loads(json_type)
        :param json_type:
        :return:
        """
        try:
            str_types = (str, unicode)
        except NameError:
            str_types = (str,)

        if type(json_type) == dict:
            return json_type
        elif type(json_type) in str_types:
            return json.loads(json_type)
        else:
            raise ValueError("json_type should be a json dict or string.")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号