When using the command-Number output interface test results, it is found that it cannot be displayed in the desired JSON format. Find out more about Python's own powerful tools.
Directly on the code:
Import=="echo '%s ' | Python-m json.tool" % contentprint os.system (command)
The result of the perfect output JSON format will no longer be copied to the online JSON conversion tool.
A brief description of the JSON module for Python:
The JSON contains two very important functions dumps and loads
Json.dumps (str) Converts the Python data type str into a JSON string
Json.loads (str) converts a JSON string into a Python data type
Additional command mate output when using functions as function
For example Json.dumps (Paras,[sort_keys,indent])
Where Sort_keys is the JSON string is sorted by key, indent is the result of each line of indentation processing
>>> Import json>>> data = {' B ': 2, ' a ': 1, ' C ':2}>>> json.dumps (data,sort_keys=true) ' {"A": 1, " B ": 2," C ": 2} '
>>> Import json>>> data = {' B ': 2, ' a ': 1, ' C ':2}>>> json.dumps (data,sort_keys=true,indent=2) ' {\ n ' A ': 1, \ n ' B ': 2, \ n ' C ': 2\n} '
This article references: http://www.cnblogs.com/kaituorensheng/p/3877382.html;http://www.cnblogs.com/wangyayun/p/6699184.html?utm_ Source=tuicool&utm_medium=referral
Python displays results in JSON format under UNIX