Description of Python's json module

高洛峰
Release: 2017-03-14 15:31:31
Original
1367 people have browsed it

This article introduces the json module description about Python

Introduction

For people who do web development, json text must 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
Copy after login

json 4 commonly used functions
'dump'
'dumps'
' load'
'loads'

Among them, 'dump' is paired 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.

The above is the detailed content of Description of Python's json module. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!