您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python3 处理JSON的实例详解

5b51 2022/1/14 8:16:14 python 字数 1663 阅读 296 来源 www.jb51.cc/python

Python3处理JSON的实例详解 真的好简单,灰常简单 importos,io,sys,re,time,base64,json importwebbrowser,urllib.request

概述

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数据  

 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()

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持

总结

以上是编程之家为你收集整理的Python3 处理JSON的实例详解全部内容,希望文章能够帮你解决Python3 处理JSON的实例详解所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶