python模块学习---json

import os,io,sys,re,time,base64,json
import webbrowser,urllib.request


def 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:/simplejson

3。安装

如下内容为Simplejson安装过程…
D:/simplejson>python setup.py install
OVER
开始提示”Python不是内部或外部命令命令“ 添加环境变量就行了。添加到path。


你可能感兴趣的:(json,python)