Home > Backend Development > Python Tutorial > How to install demjson python? Introduction to the usage of dem indicator

How to install demjson python? Introduction to the usage of dem indicator

Tomorin
Release: 2018-08-17 14:45:21
Original
4293 people have browsed it

Demjson is a third-party module library for python, which can be used to encode and decode JSON data, including the formatting and verification functions of JSONLint .

Github address: https://github.com/dmeranda/demjson

Official address: http://deron.meranda.us/python/ demjson/

Environment configuration

Before using Demjson to encode or decode JSON data, we need to install the Demjson module first. In this tutorial we will download Demjson and install it:

$ tar -xvzf demjson-2.2.3.tar.gz
$ cd demjson-2.2.3
$ python setup.py install
Copy after login

For more installation introduction: http://deron.meranda.us/python/demjson/install

JSON function

How to install demjson python? Introduction to the usage of dem indicator

##encode

Python encode( ) function is used to encode Python objects into JSON strings.

Syntax

demjson.encode(self, obj, nest_level=0)
Copy after login

Example

The following example encodes an array For JSON format data:

#!/usr/bin/python
import demjson
data = [ { 'a' : 1, 'b' : 2, 'c' : 3, 'd' : 4, 'e' : 5 } ]

json = demjson.encode(data)
print json
Copy after login

The execution result of the above code is:

[{"a":1,"b":2,"c":3,"d":4,"e":5}]
Copy after login


The above is the detailed content of How to install demjson python? Introduction to the usage of dem indicator. 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