python接口自动化5-Json数据处理
#####################################
1.首先说下为什么要encode,python里面bool值是True和False,json里面bool值是true和false,并且区分大小写,这就尴尬了,明明都是bool值。 在python里面写的代码,传到json里,肯定识别不了,所以需要把python的代码经过encode后成为json可识别的数据类型。 2.举个简单例子,下图中dict类型经过json.dumps()后变成str,True变成了true,False变成了fasle
######################################
updatetheme = {
"data": {
"type": "threads",
"attributes": {
"isApproved": 1,
"isSticky": True,
"isEssence": True,
"isDeleted": False,
"isFavorite": True
}
},
"relationships": {
"category": {
"data": {
"type": "categories",
"id": "3"
}
}
}
}
import json
print(updatetheme)
#
updatetheme = json.dumps(updatetheme)
print(updatetheme)###############################################
########################################