This article mainly explains in detail the relevant information introduced by Python’s standard module package json. Friends in need can refer to the following
Introduction
For those who do web development, json text must be familiar with and skillfully used. The data returned by the APIinterface calls of most websites is in json format. If you look at the contents of the jsonobject, I believe that for those who are familiar with Python, they will soon be able to match the jsondata type with the Python data type.
So, what is the use of Python’s standard module package json? Why do you need to convert the json format to the corresponding format of Python? Why can't we use the data in json format directly? Aren't their types almost the same and corresponding?
In fact, just by looking carefully at the data structure, you can still see that there are subtle differences between the original json format and several Python data types. Here, first list the corresponding formats for mutual conversion between the two:
Python ==> json dict object list, tuple array str, unicode string int, long, float number True true False false None null json ==> Python object dict array list string unicode number(int) int, long number(real) float true True false False
json 4 commonly used functions
'dump' 'dumps' 'load' 'loads'
Among them, 'dump' is used in conjunction with 'load', which is mainly suitable for situations where the data is large. 'dumps' and 'loads' are suitable for strings or when the data is small. Mainly, the former is written into a file for saving after conversion, while the latter is directly loaded into memory after conversion.
To be continued ^_^
The above is the detailed content of Detailed explanation of Python's standard module package json introduction. For more information, please follow other related articles on the PHP Chinese website!