Detailed explanation of Python's standard module package json introduction

高洛峰
Release: 2017-03-14 13:18:03
Original
1479 people have browsed it

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
Copy after login

json 4 commonly used functions


'dump'

'dumps'

'load'

'loads'
Copy after login

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!

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!