• MongoDB ObjectId类型 序列化问题


    MongoDB ObjectId类型 序列化问题

    data = mongo的Bson数据

    import json
    from bson import json_util
    data = json.loads(
        json.dumps(
            data,
            sort_keys=False,
            indent=4,
            default=json_util.default)
        )
    

    JSON (JavaScript Object Notation)

    http://json.org is a subset of
    JavaScript syntax (ECMA-262 3rd edition) used as a lightweight data
    interchange format.

    Pretty printing::
    
        >>> import json
        >>> print(json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4))
        {
            "4": 5,
            "6": 7
        }
    

    json.dumps()

    If ``indent`` is a non-negative integer, then JSON array elements and
    object members will be pretty-printed with that indent level. An indent
    level of 0 will only insert newlines. ``None`` is the most compact
    representation.
    
    ``default(obj)`` is a function that should return a serializable version
    of obj or raise TypeError. The default simply raises TypeError.
    
    If *sort_keys* is true (default: ``False``), then the output of
    dictionaries will be sorted by key.
  • 相关阅读:
    nyist 541最强DE 战斗力
    nyist 231 Apple Tree
    nyist 543 遥 控 器
    nyist 233 Sort it
    nyist 517 最小公倍数
    hdu 1sting
    nyist A+B Problem IV
    nyist 522 Interval
    nyist 117 求逆序数
    nyist 600 花儿朵朵
  • 原文地址:https://www.cnblogs.com/justblue/p/13543105.html
Copyright © 2020-2023  润新知