Python standard module package json details
- 2020-05-26 09:38:22
- OfStack
The introduction
For anyone doing web development, the json text must be familiar and familiar. Most web site API interface calls return data in json format. If you look at the contents of the json object, you can easily match the data type of json to the data type of Python if you are familiar with Python.
So what's the use of Python's standard module package, json? Why convert json to Python? Why can't you just use json data? Isn't its type almost identical and corresponding?
In fact, a closer look at the data structure reveals a slight difference between the original json format and several data types of Python. Here, the corresponding format of the conversion between the two is listed:
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 USES four functions
'dump'
'dumps'
'load'
'loads'
Among them, 'dump' is paired with 'load', which is mainly applicable to situations with large data. 'dumps' and 'loads' apply to small strings or data. The former is mainly saved after converting to write files, while the latter is directly loaded in memory after converting.
To be continued ^_^