Import JSON is required to introduce modules when using JSON modules
Json.dumps () Module functions
Function: converts Python data type to string "parameter"
How to use:json.dumps (data type variable to convert)
Format such as: json.dumps (yhxxi)
#!/usr/bin/env python#-*-coding:utf8-*-ImportJSONYHXXI= {#Create a nested dictionary1:{ "Yonghu":"Liguixiou", "Mima":"12345", "Youjian":"[email protected]", "Zichan": 700, }, 2:{ "Yonghu":"LIGUIXIOU2", "Mima":"123452", "Youjian":"[email protected]", "Zichan": 7002, }} A= Json.dumps (yhxxi)#Convert a dictionary to a string formatPrint(a)#print the converted string formatb = Open ("Yh.txt","W")#to open a file in write modeB.write (a)#writes a converted string to a fileB.close ()#Close an open file#Output#{"1": {"youjian": "[email protected]", "yonghu": "liguixiou", "mima": "12345", "zichan":}, "2": {"youjian": "[ema Il protected] "," yonghu ":" liguixiou2 "," mima ":" 123452 "," zichan ": 7002}}
Section 35th, JSON data type conversion string module