Traditional Culture Encyclopedia - Weather inquiry - How does python read the contents of json files?

How does python read the contents of json files?

JSON(JavaScript Object Notation) is a lightweight data exchange format. It is based on a subset of ECMAScript. JSON adopts a completely language-independent text format, but it also uses habits similar to the C language family (including C, C++, Java, JavaScript, Perl, Python, etc.). These characteristics make JSON an ideal data exchange language. It is convenient for people to read and write, and it is also convenient for machine analysis and generation (generally used to improve network transmission rate).

JSON consists of list and dict in python.

These are two modules for serialization:

Json: Used for conversion between strings and python data types.

Pickle: Used to convert between python-specific types and python data types.

The Json module provides four functions: dumps, dumps, loads and load.

The pickle module provides four functions: dump, dump, load and load.

Json Dump Converts a Data Type to a String Dump Converts a Data Type to a String and stores it in a file? Converts a string to a data type. Load converts file opening from string to data type.

Json can exchange data between different languages, while pickle is only used between python. Json can only serialize the most basic data types, while josn can only serialize common data types (list, dictionary, list, string, number,) such as date format and class object! Qiao Sen can't. Pickle can serialize all data types, including classes and functions.

Example:

Dump: Convert the dictionary in python into a string.

1importjson23test _ dict = {'bigberg':]}] 5print (load _ dict) 67 with open ("../config/record.json", "w") as dump_f:8 json.dump(load_dict, dump_f).