爬蛇的博客  
import json

s='{"name":"wuxie","sex":"m","data":null}'
dict1=json.loads(s)#load 字符串转字典。可将null变为none
print(type(dict1),dict1)
#---------------------------------------------
d={"name":"wuxie","sex":"m","data":None}
str1=json.dumps(d)#字典转字符串,可将none变为null
print(type(str1),str1)

----------------运行结果-------------
<class 'dict'> {'name': 'wuxie', 'sex': 'm', 'data': None}
<class 'str'> {"name": "wuxie", "sex": "m", "data": null}

  

import requests
import json
get_result=requests.get("http://v.juhe.cn/certificates/typeList.php",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)#字典转字符串,将none转变为null,ascii编码为true时,请求信息是乱码
#解决乱码
# s=json.dumps(get_result.json(),ensure_ascii=False)#ASCII编码改为False
print(s)
print(post_result.text)

--------运行结果-------------

{"resultcode": "101", "reason": "\u9519\u8bef\u7684\u8bf7\u6c42KEY", "result": null, "error_code": 10001}
{
	"reason":"操作成功",
	"error_code":0,
	"result":{
		"1":"一代身份证",
		"2":"二代身份证正面",
		"3":"二代身份证证背面",
		"4":"临时身份证",
		"5":"驾照",
		"6":"行驶证",
		"7":"军官证",
		"9":"中华人民共和国往来港澳通行证(护照幅面)",
		"10":"台湾居民往来大陆通行证(护照幅面)",
		"11":"大陆居民往来台湾通行证(护照幅面)",
		"12":"签证(护照幅面)",
		"13":"护照(护照幅面)",
		"14":"港澳居民来往内地通行证正面(卡幅面)",
		"15":"港澳居民来往内地通行证背面(卡幅面)",
		"16":"户口本",
		"17":"银行卡",
		"19":"车牌",
		"20":"名片",
		"22":"卡式港澳台通行证",
		"25":"新版台湾居民往来大陆通行证正面",
		"26":"新版台湾居民往来大陆通行证背面",
		"28":"中国驾驶证副页",
		"101":"二代身份证正面背面自动分类",
		"1000":"居住证",
		"1001":"香港永久性居民身份证",
		"1002":"登机牌(拍照设备目前不支持登机牌的识别)",
		"1003":"边民证(A)(照片页)",
		"1004":"边民证(B)(个人信息页)",
		"1005":"澳门身份证",
		"1006":"领取凭证(AVA6支持)",
		"1007":"律师证(A)(信息页",
		"1008":"律师证(B) (照片页)",
		"1030":"全民健康保险卡",
		"1031":"台湾身份证正面",
		"1032":"台湾身份证背面",
		"2007":"VIN码",
		"2008":"营业执照"
	}
}

  

posted on 2019-07-26 00:37  爬蛇  阅读(822)  评论(0编辑  收藏  举报