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


Python json.decoder方法代码示例

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


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

示例1: split_buffer

# 需要导入模块: import json [as 别名]
# 或者: from json import decoder [as 别名]
def split_buffer(stream, splitter=None, decoder=lambda a: a):
    """Given a generator which yields strings and a splitter function,
    joins all input, splits on the separator and yields each chunk.
    Unlike string.split(), each chunk includes the trailing
    separator, except for the last one if none was found on the end
    of the input.
    """
    splitter = splitter or line_splitter
    buffered = six.text_type('')

    for data in stream_as_text(stream):
        buffered += data
        while True:
            buffer_split = splitter(buffered)
            if buffer_split is None:
                break

            item, buffered = buffer_split
            yield item

    if buffered:
        try:
            yield decoder(buffered)
        except Exception as e:
            raise StreamParseError(e) 
开发者ID:QData,项目名称:deepWordBug,代码行数:27,代码来源:json_stream.py

示例2: split_buffer

# 需要导入模块: import json [as 别名]
# 或者: from json import decoder [as 别名]
def split_buffer(stream, splitter=None, decoder=lambda a: a):
    """Given a generator which yields strings and a splitter function,
    joins all input, splits on the separator and yields each chunk.

    Unlike string.split(), each chunk includes the trailing
    separator, except for the last one if none was found on the end
    of the input.
    """
    splitter = splitter or line_splitter
    buffered = six.text_type('')

    for data in stream_as_text(stream):
        buffered += data
        while True:
            buffer_split = splitter(buffered)
            if buffer_split is None:
                break

            item, buffered = buffer_split
            yield item

    if buffered:
        yield decoder(buffered) 
开发者ID:openai,项目名称:universe,代码行数:25,代码来源:utils.py

示例3: readJson

# 需要导入模块: import json [as 别名]
# 或者: from json import decoder [as 别名]
def readJson():
    supporters_file = os.path.join(resources_dir, "supporters.json")

    # print('READING FILE')

    if not os.path.isfile(supporters_file):
        print("SUPPORTER LIST FILE NOT FOUND!")
        return

    # print("SUPPORTER LIST FILE FOUND!")
    try:
        with open(supporters_file, encoding="utf8") as f:
            data = json.load(f)
    except json.decoder.JSONDecodeError:
        print("JSON COULD NOT BE READ")
        return

    global supporter_data
    supporter_data = data 
开发者ID:GiveMeAllYourCats,项目名称:cats-blender-plugin,代码行数:21,代码来源:supporter.py

示例4: return_if_object

# 需要导入模块: import json [as 别名]
# 或者: from json import decoder [as 别名]
def return_if_object(module, response):
    # If not found, return nothing.
    if response.status_code == 404:
        return None

    # If no content, return nothing.
    if response.status_code == 204:
        return None

    try:
        module.raise_for_status(response)
        result = response.json()
    except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
        module.fail_json(msg="Invalid JSON response with error: %s" % inst)

    if navigate_hash(result, ['error', 'errors']):
        module.fail_json(msg=navigate_hash(result, ['error', 'errors']))

    return result 
开发者ID:ansible-collections,项目名称:google.cloud,代码行数:21,代码来源:gcp_sourcerepo_repository_info.py

示例5: return_if_object

# 需要导入模块: import json [as 别名]
# 或者: from json import decoder [as 别名]
def return_if_object(module, response, allow_not_found=False):
    # If not found, return nothing.
    if allow_not_found and response.status_code == 404:
        return None

    # If no content, return nothing.
    if response.status_code == 204:
        return None

    try:
        module.raise_for_status(response)
        result = response.json()
    except getattr(json.decoder, 'JSONDecodeError', ValueError):
        module.fail_json(msg="Invalid JSON response with error: %s" % response.text)

    if navigate_hash(result, ['error', 'errors']):
        module.fail_json(msg=navigate_hash(result, ['error', 'errors']))

    return result 
开发者ID:ansible-collections,项目名称:google.cloud,代码行数:21,代码来源:gcp_runtimeconfig_config.py

示例6: return_if_object

# 需要导入模块: import json [as 别名]
# 或者: from json import decoder [as 别名]
def return_if_object(module, response, kind, allow_not_found=False):
    # If not found, return nothing.
    if allow_not_found and response.status_code == 404:
        return None

    # If no content, return nothing.
    if response.status_code == 204:
        return None

    try:
        module.raise_for_status(response)
        result = response.json()
    except getattr(json.decoder, 'JSONDecodeError', ValueError):
        module.fail_json(msg="Invalid JSON response with error: %s" % response.text)

    if navigate_hash(result, ['error', 'errors']):
        module.fail_json(msg=navigate_hash(result, ['error', 'errors']))

    return result 
开发者ID:ansible-collections,项目名称:google.cloud,代码行数:21,代码来源:gcp_compute_disk.py

示例7: return_if_object

# 需要导入模块: import json [as 别名]
# 或者: from json import decoder [as 别名]
def return_if_object(module, response, allow_not_found=False):
    # If not found, return nothing.
    if allow_not_found and response.status_code == 404:
        return None

    # If no content, return nothing.
    if response.status_code == 204:
        return None

    try:
        module.raise_for_status(response)
        result = response.json()
    except getattr(json.decoder, 'JSONDecodeError', ValueError):
        module.fail_json(msg="Invalid JSON response with error: %s" % response.text)

    result = decode_response(result, module)

    if navigate_hash(result, ['error', 'errors']):
        module.fail_json(msg=navigate_hash(result, ['error', 'errors']))

    return result 
开发者ID:ansible-collections,项目名称:google.cloud,代码行数:23,代码来源:gcp_kms_key_ring.py

示例8: return_if_object

# 需要导入模块: import json [as 别名]
# 或者: from json import decoder [as 别名]
def return_if_object(module, response):
    # If not found, return nothing.
    # return_if_object not used in any context where 404 means error.
    if response.status_code == 404:
        return None

    # If no content, return nothing.
    if response.status_code == 204:
        return None

    try:
        module.raise_for_status(response)
        result = response.json()
    except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
        module.fail_json(msg="Invalid JSON response with error: %s" % inst)

    if navigate_hash(result, ['error', 'errors']):
        module.fail_json(msg=navigate_hash(result, ['error', 'errors']))

    return result 
开发者ID:ansible-collections,项目名称:google.cloud,代码行数:22,代码来源:gcp_iam_service_account_key.py

示例9: return_if_object

# 需要导入模块: import json [as 别名]
# 或者: from json import decoder [as 别名]
def return_if_object(module, response, kind, allow_not_found=False):
    # If not found, return nothing.
    if allow_not_found and response.status_code == 404:
        return None

    # If no content, return nothing.
    if response.status_code == 204:
        return None

    try:
        module.raise_for_status(response)
        result = response.json()
    except getattr(json.decoder, 'JSONDecodeError', ValueError):
        module.fail_json(msg="Invalid JSON response with error: %s" % response.text)

    result = decode_response(result, module)

    if navigate_hash(result, ['error', 'errors']):
        module.fail_json(msg=navigate_hash(result, ['error', 'errors']))

    return result 
开发者ID:ansible-collections,项目名称:google.cloud,代码行数:23,代码来源:gcp_compute_instance.py

示例10: return_if_object

# 需要导入模块: import json [as 别名]
# 或者: from json import decoder [as 别名]
def return_if_object(module, response, kind, allow_not_found=False):
    # If not found, return nothing.
    if allow_not_found and response.status_code == 404:
        return None

    # If no content, return nothing.
    if response.status_code == 204:
        return None

    # SQL only: return on 403 if not exist
    if allow_not_found and response.status_code == 403:
        return None

    try:
        result = response.json()
    except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
        module.fail_json(msg="Invalid JSON response with error: %s" % inst)

    if navigate_hash(result, ['error', 'errors']):
        module.fail_json(msg=navigate_hash(result, ['error', 'errors']))

    return result 
开发者ID:ansible-collections,项目名称:google.cloud,代码行数:24,代码来源:gcp_sql_instance.py


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