python_json library

json library

import json
dir(json)

result:
['JSONDecodeError',
 'JSONDecoder',
 'JSONEncoder',
 '__all__',
 '__author__',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__',
 '__version__',
 '_default_decoder',
 '_default_encoder',
 'codecs',
 'decoder',
 'detect_encoding',
 'dump',
 'dumps',
 'encoder',
 'load',
 'loads',
 'scanner']

Encode into json data

name Coding result effect
dump file stream Encode python objects into json data
dumps string

dump

dump(obj, fp, *, 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`` as a JSON formatted stream to ``fp`` (a
    ``.write()``-supporting file-like object)

obj, conversion object
skipkeys, default is false, when true, dict is not a basic type, str, int, float, bool, none will not cause type errors, but will not skip
ensure_ascii, default is true, output ASCII code, is When true, Chinese
check_circular can be output.

dumps

Decode into python object

name Operation object effect
load file stream Decode json data into python object
loads string

Parameter "strict=False", control characters are allowed in strings, the default is True

load

loads

Error message

Errors like this occur, usually because the format is not standard

JSONDecodeError: Expecting ',' delimiter: line 1 column 38 (char 37)

json data formatting

https://www.json.cn/

Guess you like

Origin blog.csdn.net/WEB___/article/details/132204428