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

更多QQ空间微信QQ好友腾讯朋友复制链接
您的位置:首頁/技術文章
文章詳情頁

Python json格式化打印實現過程解析

【字号: 作者:豬豬瀏覽:2日期:2022-07-16 17:31:31

編寫python腳本,調試的時候需要打印json格式報文,直接打印看不出層次,可以使用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對象,indent表示縮進,ensure_ascii設置編碼格式化打印前:

格式化打印前:

Python json格式化打印實現過程解析

格式化打印后:

Python json格式化打印實現過程解析

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)

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 欧美在线国产 | 欧美黄色特级视频 | 97色婷婷成人综合在线观看 | 日本免费大黄在线观看 | 麻豆免费永久网址入口网址 | 美国一级做a一级爱视频 | 国产精品日本不卡一区二区 | 最新在线精品国自拍视频 | 欧美特黄a级高清免费大片 欧美特黄a级高清免费看片 | 欧美色碰碰碰免费观看长视频 | 成人区精品一区二区不卡亚洲 | 美女批日起爽在线观看 | 美女黄网站人色视频免费国产 | 亚洲成a人片在线观看中文动漫 | 国产日韩欧美综合 | 日本精品视频一区二区三区 | 久久国产成人 | 女人色毛片女人色毛片中国 | 这里是九九伊人 | 国产美女视频一区二区二三区 | 欧美日韩精品一区二区三区 | 成年人午夜免费视频 | 女人被狂躁视频免费网站 | 午夜日韩久久影院 | 国产视频1区 | 国产一级视频在线观看网站 | 国产xx做受视频国语对白 | 国产一二三区四区乱码2021 | 一级黄色免费大片 | 欧美成人性色大片在线观看 | 青青草91在线 | 全部费免一级毛片不收费 | 日韩精品福利视频一区二区三区 | 91视频三级 | 亚洲国产综合精品中文第一区 | 亚洲3级| 免费一级毛片正在播放 | 免费看成人国产一区二区三区 | 久青草视频97国内免费影视 | 日本护士一级毛片在线播放 | 色啊色 |