前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python 美化打印 json 数据

Python 美化打印 json 数据

作者头像
py3study
发布2020-01-10 15:28:12
1.4K0
发布2020-01-10 15:28:12
举报
文章被收录于专栏:python3

正常获取 JSON 数据,数据的显示格式较为混乱,无法直视

可以采用浏览器插件方式需要安装 Chrome 插件:JSONView

curl http://m.weather.com.cn/data/101210101.html

代码语言:javascript
复制
{"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

代码语言:javascript
复制
% 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"
    }
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/07/30 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
命令行工具
腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档