python模块学习---json

来源:互联网 发布:js微信授权获取code 编辑:程序博客网 时间:2024/05/16 17:30
import os,io,sys,re,time,base64,jsonimport webbrowser,urllib.requestdef main():    url = "http://m.weather.com.cn/data/101010100.html"    stdout = urllib.request.urlopen(url)    weatherinfo = stdout.read().decode('utf-8')    jsonData = json.loads(weatherinfo)        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()

在python2.x中有simplejson模块,python3.x中为json


2.7 安装simplejson步骤:

windows xp环境下,总共3个步骤:1。 下载http://pypi.python.org/pypi/simplejson/2。解压例如:下面例子解压到:D:/simplejson3。安装如下内容为Simplejson安装过程…D:/simplejson>python setup.py installOVER开始提示”Python不是内部或外部命令命令“ 添加环境变量就行了。添加到path。


0 0
原创粉丝点击