Python 美化打印 json 数据
正常获取 JSON 数据,数据的显示格式较为混乱,无法直视
可以采用浏览器插件方式需要安装 Chrome 插件:jsONView
curl Http://m.weather.com.cn/data/101210101.html
{"weatherinfo":{"city":"杭州","city_en":"hangzhou","date_y":"2013年10月12日","date":"","week":"星期六","fchh":"11","cityid":"101210101","temp1":"28℃~18℃","temp2":"29℃~19℃","temp3":"29℃~17℃","temp4":"19℃~12℃","temp5":"17℃~11℃","temp6":"18℃~12℃","tempF1":"82.4℉~64.4℉","tempF2":"84.2℉~66.2℉","tempF3":"84.2℉~62.6℉","tempF4":"66.2℉~53.6℉","tempF5":"62.6℉~51.8℉","tempF6":"64.4℉~53.6℉","weather1":"多云转晴","weather2":"多云转晴","weather3":"多云转阴","weather4":"阵雨转阴","weather5":"多云","weather6":"多云","img1":"1","img2":"0","img3":"1","img4":"0","img5":"1","img6":"2","img7":"3","img8":"2","img9":"1","img10":"99","img11":"1","img12":"99","img_single":"1","img_title1":"多云","img_title2":"晴","img_title3":"多云","img_title4":"晴","img_title5":"多云","img_title6":"阴","img_title7":"阵雨","img_title8":"阴","img_title9":"多云","img_title10":"多云","img_title11":"多云","img_title12":"多云","img_title_single":"多云","wind1":"东北风小于3级","wind2":"东风小于3级","wind3":"东南风小于3级","wind4":"东北风4-5级转小于3级","wind5":"东风小于3级","wind6":"东风小于3级","fx1":"东北风","fx2":"东北风","fl1":"小于3级","fl2":"小于3级","fl3":"小于3级","fl4":"4-5级转小于3级","fl5":"小于3级","fl6":"小于3级","index":"热","index_d":"天气热,建议着短裙、短裤、短薄外套、T恤等夏季服装。","index48":"热","index48_d":"天气热,建议着短裙、短裤、短薄外套、T恤等夏季服装。","index_uv":"中等","index48_uv":"中等","index_xc":"适宜","index_tr":"适宜","index_co":"较舒适","st1":"29","st2":"19","st3":"29","st4":"20","st5":"29","st6":"16","index_cl":"适宜","index_ls":"适宜","index_ag":"较易发"}}
使用 python 将他们美化排版一下
curl http://m.weather.com.cn/data/101210101.html | Python -mjson.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1803 0 1803 0 0 19745 0 --:--:-- --:--:-- --:--:-- 38361
{
"weatherinfo": {
"city": "\u676d\u5dde",
"city_en": "hangzhou",
"cityid": "101210101",
"date": "",
"date_y": "2013\u5e7410\u670812\u65e5",
"fchh": "11",
"fl1": "\u5c0f\u4e8e3\u7ea7",
"fl2": "\u5c0f\u4e8e3\u7ea7",
"fl3": "\u5c0f\u4e8e3\u7ea7",
"fl4": "4-5\u7ea7\u8f6c\u5c0f\u4e8e3\u7ea7",
"fl5": "\u5c0f\u4e8e3\u7ea7",
"fl6": "\u5c0f\u4e8e3\u7ea7",
"fx1": "\u4e1c\u5317\u98ce",
"fx2": "\u4e1c\u5317\u98ce",
"img1": "1",
"img10": "99",
"img11": "1",
"img12": "99",
"img2": "0",
"img3": "1",
"img4": "0",
"img5": "1",
"img6": "2",
"img7": "3",
"img8": "2",
"img9": "1",
"img_single": "1",
"img_title1": "\u591a\u4e91",
"img_title10": "\u591a\u4e91",
"img_title11": "\u591a\u4e91",
"img_title12": "\u591a\u4e91",
"img_title2": "\u6674",
"img_title3": "\u591a\u4e91",
"img_title4": "\u6674",
"img_title5": "\u591a\u4e91",
"img_title6": "\u9634",
"img_title7": "\u9635\u96e8",
"img_title8": "\u9634",
"img_title9": "\u591a\u4e91",
"img_title_single": "\u591a\u4e91",
"index": "\u70ed",
"index48": "\u70ed",
"index48_d": "\u5929\u6c14\u70ed\uff0c\u5efa\u8bae\u7740\u77ed\u88d9\u3001\u77ed\u88e4\u3001\u77ed\u8584\u5916\u5957\u3001T\u6064\u7b49\u590f\u5b63\u670d\u88c5\u3002",
"index48_uv": "\u4e2d\u7b49",
"index_ag": "\u8f83\u6613\u53D1",
"index_cl": "\u9002\u5b9c",
"index_co": "\u8f83\u8212\u9002",
"index_d": "\u5929\u6c14\u70ed\uff0c\u5efa\u8bae\u7740\u77ed\u88d9\u3001\u77ed\u88e4\u3001\u77ed\u8584\u5916\u5957\u3001T\u6064\u7b49\u590f\u5b63\u670d\u88c5\u3002",
"index_ls": "\u9002\u5b9c",
"index_tr": "\u9002\u5b9c",
"index_uv": "\u4e2d\u7b49",
"index_xc": "\u9002\u5b9c",
"st1": "29",
"st2": "19",
"st3": "29",
"st4": "20",
"st5": "29",
"st6": "16",
"temp1": "28\u2103~18\u2103",
"temp2": "29\u2103~19\u2103",
"temp3": "29\u2103~17\u2103",
"temp4": "19\u2103~12\u2103",
"temp5": "17\u2103~11\u2103",
"temp6": "18\u2103~12\u2103",
"tempF1": "82.4\u2109~64.4\u2109",
"tempF2": "84.2\u2109~66.2\u2109",
"tempF3": "84.2\u2109~62.6\u2109",
"tempF4": "66.2\u2109~53.6\u2109",
"tempF5": "62.6\u2109~51.8\u2109",
"tempF6": "64.4\u2109~53.6\u2109",
"weather1": "\u591a\u4e91\u8f6c\u6674",
"weather2": "\u591a\u4e91\u8f6c\u6674",
"weather3": "\u591a\u4e91\u8f6c\u9634",
"weather4": "\u9635\u96e8\u8f6c\u9634",
"weather5": "\u591a\u4e91",
"weather6": "\u591a\u4e91",
"week": "\u661f\u671f\u516d",
"wind1": "\u4e1c\u5317\u98ce\u5c0f\u4e8e3\u7ea7",
"wind2": "\u4e1c\u98ce\u5c0f\u4e8e3\u7ea7",
"wind3": "\u4e1c\u5357\u98ce\u5c0f\u4e8e3\u7ea7",
"wind4": "\u4e1c\u5317\u98ce4-5\u7ea7\u8f6c\u5c0f\u4e8e3\u7ea7",
"wind5": "\u4e1c\u98ce\u5c0f\u4e8e3\u7ea7",
"wind6": "\u4e1c\u98ce\u5c0f\u4e8e3\u7ea7"
}
}
相关文章