Basics python --- Json function

Using JSON json library functions need to import: Import json .

   Function Description 
json.dumps the Python object encoded as JSON string 
json.loads the encoded JSON string decoded Python object

json.dumps

Python json.dumps for encoding objects into JSON string.

The following examples array coded JSON format data: 

# / usr / bin / Python! 
Import JSON 

Data = [{ ' A ' :. 1, ' B ' : 2, ' C ' :. 3, ' D ' :. 4, ' E ' :. 5 }] 

JSON = json.dumps (Data)
 Print JSON

 

 

json.loads

json.loads JSON data for decoding. This function returns the field data type Python.

import json

jsonData = '{"a":1,"b":2,"c":3,"d":4,"e":5}';

text = json.loads(jsonData)
print text

 

Guess you like

Origin www.cnblogs.com/qjhh/p/12593686.html