Example sharing of Python parsing JSON

小云云
Release: 2018-03-30 16:43:24
Original
1702 people have browsed it

This article mainly shares with you examples of Python parsing JSON, mainly explaining it in the form of code, hoping to help everyone

JSON (JavaScript Object Notation, JS object mark) is a lightweight data exchange format.
Python needs to import the json library to use the JSON function:
import json.

json.dumps
json.dumps is used to encode Python objects into JSON strings.

Syntax
json.dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, encoding="utf-8 ", default=None, sort_keys=False, **kw)
Example

data = [ { 'a' : 1, 'b' : 2, 'c' : 3, 'd' : 4, 'e' : 5 } ]
json = json.dumps(data)
print(json)

dict = {"name":"Tom", "age":23} 
a = json.dumps(dict)
print(a)
Copy after login

json.loads
json.loads is used to decode JSON data. This function returns the data type of the Python field.

Syntax
json.loads(s[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, **kw]]]]]]]])
Example

t = json.loads(a)
print(t)

Related recommendations:

Jackson uppercase and lowercase when parsing json string Automatic conversion method

js method of reading and parsing JSON data

Example tutorial of parsing JSON data with jQuery

The above is the detailed content of Example sharing of Python parsing JSON. 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!