亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Python json格式化打印實(shí)現(xiàn)過(guò)程解析

瀏覽:3日期:2022-07-16 17:31:31

編寫python腳本,調(diào)試的時(shí)候需要打印json格式報(bào)文,直接打印看不出層次,可以使用json.dumps格式化打印

import jsonimport requestsdef test_json(): r=requests.get(’https://home.testing-studio.com/categories.json’) print(r.json()) print(json.dumps(r.json(), indent=2,ensure_ascii=False)) # r.json()是json對(duì)象,indent表示縮進(jìn),ensure_ascii設(shè)置編碼格式化打印前:

格式化打印前:

Python json格式化打印實(shí)現(xiàn)過(guò)程解析

格式化打印后:

Python json格式化打印實(shí)現(xiàn)過(guò)程解析

json.dumps方法源碼:

def dumps(obj, *, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, default=None, sort_keys=False, **kw): '''Serialize ``obj`` to a JSON formatted ``str``. If ``skipkeys`` is true then ``dict`` keys that are not basic types (``str``, ``int``, ``float``, ``bool``, ``None``) will be skipped instead of raising a ``TypeError``. If ``ensure_ascii`` is false, then the return value can contain non-ASCII characters if they appear in strings contained in ``obj``. Otherwise, all such characters are escaped in JSON strings. If ``check_circular`` is false, then the circular reference check for container types will be skipped and a circular reference will result in an ``OverflowError`` (or worse). If ``allow_nan`` is false, then it will be a ``ValueError`` to serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) in strict compliance of the JSON specification, instead of using the JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``). 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. If specified, ``separators`` should be an ``(item_separator, key_separator)`` tuple. The default is ``(’, ’, ’: ’)`` if *indent* is ``None`` and ``(’,’, ’: ’)`` otherwise. To get the most compact JSON representation, you should specify ``(’,’, ’:’)`` to eliminate whitespace. ``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. To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the ``.default()`` method to serialize additional types), specify it with the ``cls`` kwarg; otherwise ``JSONEncoder`` is used. ''' # cached encoder if (not skipkeys and ensure_ascii and check_circular and allow_nan and cls is None and indent is None and separators is None and default is None and not sort_keys and not kw): return _default_encoder.encode(obj) if cls is None: cls = JSONEncoder return cls( skipkeys=skipkeys, ensure_ascii=ensure_ascii, check_circular=check_circular, allow_nan=allow_nan, indent=indent, separators=separators, default=default, sort_keys=sort_keys, **kw).encode(obj)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 国内精品久久久久激情影院 | 国产综合日韩伦理 | 精品视频网| 亚洲精品久久久久福利网站 | 日韩成人性视频 | 麻豆网站视频国产在线观看 | 麻豆射区 | 成人精品在线视频 | 一级黄色片美国 | 欧美第二区 | 日本特黄特色大片免费视频观看 | 国产午夜三级 | 老司机日日摸夜夜摸精品影院 | 国产三级在线免费观看 | 日本一级特黄aa大片在线观看 | 黄大色黄美女精品大毛片 | 国产影片中文字幕 | 亚洲色综合图区p | 亚洲精品99久久久久久欧美版 | 成年性羞羞视频免费观看无限 | 久久精品日本免费线 | 青青青视频精品中文字幕 | 国产专区在线 | 人成免费 | 国产福利在线视频 | 青青热久久综合网伊人 | 欧美a级在线 | 91久久国产露脸精品免费 | 日韩爽爽视频爽爽 | 国产一级毛片大陆 | 国产成版人视频网站免费下 | 青青草原综合久久大伊人精品 | 高清毛片在线看高清 | 久热中文字幕在线精品首页 | 中文字幕成人乱码在线电影 | 深夜成人性视频免费看 | 99免费精品 | 婷婷激情综合网 | 尤物网站在线 | 成人做爰网站免费看 | 亚洲婷婷天堂在线综合 |