loads and dumps usage

JSON Import 

S = '{ "name": "wuxie", "Sex": "m", "Data": null}' 
dict1 = json.loads (S) #load turn string dictionary. Null can be changed to none 
Print (of the type (dict1), dict1) 
# ---------------------------------- ----------- 
D = { "name": "wuxie", "Sex": "m", "Data": None} 
str1 = json.dumps (D) to string # dictionary, none may become null 
Print (type (str1), str1) 

---------------- operation results ------------- 
<class' dict '> {' name ':' wuxie ',' Sex ':' m ',' Data ': None} 
<class' STR'> { "name": "wuxie", "Sex": "m", "Data ": null}

  

Requests Import 
Import JSON 
get_result = requests.get ( "http://v.juhe.cn/certificates/typeList.php", the params = { "Key": ""}) 
post_result = requests.post (URL = "HTTP: //v.juhe.cn/certificates/typeList.php",data={"key":"feff6a9dcd1191d36ae0145739c50afc "}) 
S = json.dumps (get_result.json (), ensure_ascii = True) # transfected dictionary string, when none converted to null, ascii encoding is true, the request information is garbled 
# solve distortion 
# s = json.dumps (get_result.json () , ensure_ascii = False) #ASCII coding to False 
Print (S) 
Print (post_result.text ) 

-------- operating results ------------- 

{ "ResultCode": "101", "reason": "\ u9519 \ u8bef \ u7684 \ u8bf7 \ u6c42KEY", "Result": null, "ERROR_CODE": 10001} 
{ 
	"reason":"Operation Success", 
	"ERROR_CODE": 0, 
	"the Result": {  
		". 1": "generation ID,"
		"2": "second-generation ID card front"
		"3": "second-generation ID cards on the back", 
		"4": "temporary ID card", 
		"5": "driver's license", 
		"6": "travel card", 
		"7": "military officer", 
		" 9 ":" People's Republic of China EEP (passport format) ", 
		" 10 ":" Taiwan residents traveling to the mainland passes (passport format) ", 
		" 11 ":" mainland residents to Taiwan passport (passport format) ", 
		" 12 ":" visa (passport format) ", 
		" 13 ":" passport (passport format) ", 
		" 14 ":" Hong Kong and Macao residents traveling to the mainland passes positive (card format) ", 
		" 15 ":" Hong Kong and Macao residents traveling to the mainland passes back (card format) ", 
		" 16 ":" this account ", 
		" 17 ":" card ", 
		" 19 ":" plates ", 
		" 20 ":" business card ", 
		" 22 ":" cassette Hong Kong, Macao and Taiwan pass "
		"25": "The new Taiwan residents traveling to the mainland passes positive", 
		"26": "between the mainland passes back a new version of Taiwan residents", 
		"28": "Chinese Vice driver's license Page", 
		"101": "second-generation ID card front automatic classification of the back ", 
		" 1000 ":" residence ", 
		" 1001 ":" Hong Kong permanent identity card ", 
		" 1004 ":" border certificate (B) (personal information page) "Border permit (B) (personal information page) "Border permit (B) (personal information page) " 
		" 1002 ":" boarding pass (camera equipment recognition boarding pass is not currently supported) "Boarding pass (boarding pass identifies camera device is currently not supported) "Boarding pass (boarding pass identifies camera device is currently not supported) "
		"1003": "border certificate (A) (photo page)", 
		"1005": "Macau identity card", 
		"1006": "to receive credentials (AVA6 support)", 
		"1007": "Lawyer card (A) ( information page ", 
		" 1008 ":" the Bar (B) (photo page) ", 
		" 1030 ":" National health Insurance card ", 
		" 1031 ":" Taiwan identity card front ", 
		" 1032 ":" Taiwan identity card back ", 
		" 2007 ":" VIN code ", 
		" 2008 ":" business license " 
	} 
}

  

Guess you like

Origin www.cnblogs.com/tzxy/p/11247847.html