



下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
第Python解析Json格式代碼defppt(obj,path=.,with_print=False,normal_path_print=False):
base_string=strifsix.PY3elsebasestring
obj=json.loads(obj)ifisinstance(obj,base_string)elseobj
find_str,find_map=,[[%s],[%s],%s,.%s]
foriminpath.split(.):
ifnotim:
continue
ifisinstance(obj,(list,tuple,base_string)):
ifim.startswith([)andim.endswith(]):
im=im[1:-1]
if:inim:
slice_default=[0,len(obj),1]
obj,quota=obj[slice(
*[int(sli)ifslielseslice_default[i]fori,sliin
enumerate(im.split(:))])],1
else:
obj,quota=obj[int(im)],1
else:
ifiminobj:
obj,quota=obj[im],0
elifim.endswith(()):
obj,quota=list(getattr(obj,im[:-2])()),3
else:
ifim.isdigit():
obj,quota=obj[int(im)],1
else:
rAIseKeyError(im)
find_str+=find_map[quota]%im
ifwith_print:
print(objifisinstance(obj,base_string)else
json.dumps(obj,
indent=4,
sort_keys=True,
ensure_ascii=False))
ifnormal_path_print:
print(getitnormallywith:obj%s%find_str)
returnobj
測試標(biāo)準Json內(nèi)容
importrequests
Test_Url=/api/V4/stati.data.get
Test_Code=requests.get(Test_Url).text
print(Test_Code)
print(ppt(Test_Code,.))
print(ppt(Test_Code,.status))
print(ppt(Test_Code,.status.code))
print(ppt(Test_Code,.status.message))
以下為輸出內(nèi)容:
{status:{code:16149,message:沒有登錄}}
{status:{code:16149,message:沒有登錄}}
{code:16149,message:沒有登錄}
16149
沒有登錄
測試多樣Json內(nèi)容
importrequests
Test_Url=/ps/list.json
Test_Code=requests.get(Test_Url).text
print(Test_Code)
print(ppt(Test_Code,.))
print(ppt(Test_Code,.b1))
print(ppt(Test_Code,.top.[0]))
print(ppt(Test_Code,.top.[1]))
print(ppt(Test_Code,.top.[:]))
以下為輸出內(nèi)容:
{b1:{url:https://nima.vipsojson,red:0,text:二維碼工具,type:img,img:/file/ps/1341977100,xkey:banner-1},b2:{url:,red:0,text:js加密,type:img,img:/file/ps/1044755494,xkey:banner-2},indexRight:{url:/from=,red:0,text:又拍云,type:img,img:/yyimgs/LwRTCYEAX2jKBAIvvGU61Q==/109951164031881717,xkey:index-right-275x130},top:[{url:/act/202502/202502.htmls=zzsojson,red:1,text:香港/美國服務(wù)器,限量2.5折,type:text,img:,xkey:top-text},{url:/register/invite=H1Z6578p-,red:0,text:又拍云,type:text,img:,xkey:top-text}]}
{b1:{url:https://nima.vipsojson,red:0,text:二維碼工具,type:img,img:/file/ps/1341977100,xkey:banner-1},b2:{url:,red:0,text:js加密,type:img,img:/file/ps/1044755494,xkey:banner-2},indexRight:{url:/from=,red:0,text:又拍云,type:img,img:/yyimgs/LwRTCYEAX2jKBAIvvGU61Q==/109951164031881717,xkey:index-right-275x130},top:[{url:/act/202502/202502.htmls=zzsojson,red:1,text:香港/美國服務(wù)器,限量2.5折,type:text,img:,xkey:top-text},{url:/register/invite=H1Z6578p-,red:0,text:又拍云,type:text,img:,xkey:top-text}]}
{url:https://nima.vipsojson,red:0,text:二維碼工具,type:img,img:/file/ps/1341977100,xkey:banner-1}
{url:/act/202502/202502.htmls=zzsojson,red:1,text:香港/美國服務(wù)器,限量2.5折,type:text,img:,xkey:top-text}
{url:/register/invite=H1Z6578p-,red:0,text:又拍云,type:text,img:,xkey:top-text}
[{url:/act/202502/202502.htmls=zzsojso
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年旅游管理專業(yè)實務(wù)考卷及答案
- 學(xué)區(qū)房學(xué)位鎖定與購房保障合同
- 青春偶像劇改編影視作品授權(quán)合同
- 機場航站樓精裝修房驗收標(biāo)準與保障協(xié)議
- 藝術(shù)考級項目品牌推廣與承包合作協(xié)議
- 留學(xué)歸國人員國際科技合作項目執(zhí)行聘用合同
- 零售企業(yè)智能倉儲物流系統(tǒng)開發(fā)與維護服務(wù)合同
- 網(wǎng)絡(luò)信息安全防護方案設(shè)計與實施協(xié)議
- 東南亞熱帶雨林度假村租賃及生態(tài)保護協(xié)議
- 跨國貿(mào)易進口貨物違約金計算及結(jié)算協(xié)議
- 基于PLC交流變頻調(diào)速系統(tǒng)的設(shè)計 畢業(yè)設(shè)計(論文)
- DB11-490-2007地鐵工程監(jiān)控量測技術(shù)規(guī)程高清最新版
- PROE中英文對照表
- 漢字六書課件
- 勞動爭議仲裁調(diào)解法課件
- 職場利器-陽光心態(tài)課件
- 發(fā)展少數(shù)民族醫(yī)藥實施方案
- GB∕T 20394-2019 體育用人造草
- 中考物理總復(fù)習(xí)幾點建議和思考(ppt課件)
- 乳腺的影像診斷課件
- 三峽庫區(qū)榨菜廢水污染治理技術(shù)導(dǎo)則
評論
0/150
提交評論