python-Charles返回数据转换成json或String

 

# -*- coding: utf-8 -*-

s = "app_id=110&biz_data=DSZ2HqLuZkVI09JW0ns-lQ%3D%3D&imei=5af10ceb2358b8951bad1f91bc5eb10501f8391a&method=com.insurance.handler.insurance.banner&otaKey=e86ce4752ba46a06035db951531caf2d&platform=iOS&sign=M0EqDsJ5A5a3NHkq3-KN1g%3D%3D×tamp=1559026795000&token=D1jgz4NCTwRThG3w40HQ9NohXkZDgCNQxq90Yff9DNV1buMTMCoyT12F7Tn5LVWZ_CIPKrG03IWD4xwWiwcxVN3WLmwlzHDDpQ5Y3nJrQArUaB4pA5xfRnk51otqnLcdZvpTQ3l2r5DojDLPkceggA%3D%3D&uid=6237807&version=1.8.0_177"


#charles返回的String格式数据转换成json格式
def tojson(sd):
	d = {}
	s1 = sd.split("&")
	for s2 in s1:
		s3 = s2.split("=")
		key = s3[0]
		value = s3[1]
		d[key] = value
	return d

print(tojson(s))

print("===============================================================================================================================================================")

d={
	"code": 0,
	"msg": "成功",
	"result": [{
		"imageUrl": "http://sifudefile.oss-cn-beijing.aliyuncs.com/lejian/others/health/info/1533005038830.jpg",
		"infoId": 18468,
		"likeNum": 866,
		"locationUrl": "http://lejane.jxbrty.com/html/article//20180731/20180731_18468_1533005180908.html?v=1533005180908",
		"publishDate": 1532966400000,
		"tagId": 274,
		"tagName": "老人",
		"title": "听力不好易致老年痴呆"
	}, {
		"imageUrl": "http://sifudefile.oss-cn-beijing.aliyuncs.com/lejian/others/health/info/1531278153536.jpg",
		"infoId": 17632,
		"likeNum": 1597,
		"locationUrl": "http://lejane.jxbrty.com/html/article//20180711/20180711_17632_1531278175097.html?v=1531278175097",
		"publishDate": 1531238400000,
		"tagId": 274,
		"tagName": "老人",
		"title": "老人夏季洗澡 有“四备”"
	}, {
		"imageUrl": "http://sifudefile.oss-cn-beijing.aliyuncs.com/lejian/others/health/info/1531277973575.jpg",
		"infoId": 17630,
		"likeNum": 1500,
		"locationUrl": "http://lejane.jxbrty.com/html/article//20180711/20180711_17630_1531278039808.html?v=1531278039808",
		"publishDate": 1531238400000,
		"tagId": 274,
		"tagName": "老人",
		"title": "夏季养生南北有别"
	}],
	"timestamp": "1560236913000"
}

#charles返回的josn格式数据转换成String格式
def tostring(sd):
    s1 = sd.items()
    lst = []
    for key, value in s1:
        s3 = "%s=%s" % (key, value)
        lst.append(s3)
    return "&".join(lst)
print(tostring(d))



 

你可能感兴趣的:(python)