Home  >  Article  >  Backend Development  >  Detailed explanation of the application of Json in Python

Detailed explanation of the application of Json in Python

Y2J
Y2JOriginal
2017-05-09 14:43:541374browse

This article mainly introduces relevant information about Python’s standard module package json. Friends who need it can refer to it

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' and 'load' Paired use is mainly suitable for large data situations. '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.

【Related recommendations】

1. Python Free Video Tutorial

2. Python Learning Manual

3. Python object-oriented video tutorial

The above is the detailed content of Detailed explanation of the application of Json in Python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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