當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。