Python3 處理JSON的實例詳解
更新時間:2017年10月29日 08:36:37 作者:dove1980
這篇文章主要介紹了Python3 處理JSON的實例詳解的相關資料,希望通過本文能幫助到大家,讓大家實現(xiàn)這樣的功能,需要的朋友可以參考下
Python3 處理JSON的實例詳解
真的好簡單,灰常簡單
import os, io, sys, re, time, base64, json
import webbrowser, urllib.request
def main():
"main function"
url = "http://m.weather.com.cn/data/101010100.html"
stdout=urllib.request.urlopen(url)
weatherInfo= stdout.read().decode('utf-8')
#print(weatherInfo)
jsonData = json.loads(weatherInfo)
輸出JSON數(shù)據(jù)
szCity = jsonData["weatherinfo"]["city"]
print("城市: ", szCity)
szTemp = jsonData["weatherinfo"]["temp1"]
print("溫度: ", szTemp)
szWeather1 = jsonData["weatherinfo"]["weather1"]
print("天氣情況: ",szWeather1)
szCityid = jsonData["weatherinfo"]["cityid"]
print("城市編碼: ",szCityid)
if __name__ == '__main__':
main()
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關文章
python3使用tkinter實現(xiàn)ui界面簡單實例
使用tkinter創(chuàng)建一個小窗口,布置2個按鈕,一個btn關閉窗口,另一個btn用于切換執(zhí)行傳入的2個函數(shù),簡單的小代碼,大家參考使用吧2014-01-01
Pandas如何對帶有Multi-column(多列名稱)的數(shù)據(jù)排序并寫入Excel中
這篇文章主要介紹了Pandas如何對帶有Multi-column(多列名稱)的數(shù)據(jù)排序并寫入Excel中問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-02-02
對python 通過ssh訪問數(shù)據(jù)庫的實例詳解
今天小編就為大家分享一篇對python 通過ssh訪問數(shù)據(jù)庫的實例詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-02-02
用Python寫飛機大戰(zhàn)游戲之pygame入門(4):獲取鼠標的位置及運動
這篇文章主要介紹了用Python寫飛機大戰(zhàn)游戲之pygame入門(4):獲取鼠標的位置及運動,需要的朋友可以參考下2015-11-11

