专栏首页python3Python 美化打印 json 数据

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"
    }
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • Python_二维数组

    py3study
  • django之路由分组,反向解析,有名

    路由层   无名分组   有名分组   反向解析   路由分发   名称空间   伪静态的概念

    py3study
  • 生产者与消费者+Queue(线程安全)

      如果使用threading.Lock(),或者threading.Condition(),都是线程不安全的,它们都是锁,共同方法(lock.acquire(...

    py3study
  • vue页面开发遇到的坑,都是泪!src属性,freemarker取值

    效果图如下 对应的连接 http://www.xinghengedu.com/getTenActivityQuestions.jspx 可以玩一玩。

    陈灬大灬海
  • Elasticsearch——禁止Body中的index覆盖Url中的index参数

    本篇继续一下Elasticsearch日常使用的技巧翻译。 在Elasticsearch有很多的api支持在body中指定_index等信息,比如mget...

    用户1154259
  • nginx rewrite

    rewrite的作用 rewrite可以实现url的重定向,把用户请求的url转发到另一个url,但用户浏览器地址并不改变 例如常用的伪静态化,就是通过rewr...

    dys
  • 索尼与微软建立战略合作伙伴关系,致力于云解决方案与人工智能

    索尼公司和微软公司宣布,两家公司将合作开展新的创新,以增强其直接面向消费者的娱乐平台和人工智能解决方案带来的客户体验。

    AiTechYun
  • 三分钟基础知识:什么是栈?

    对于栈的认识,相信每个学习数据结构的小伙伴多多少少有一定的认识和了解。很多刚刚学习的小伙伴说学习数据结构在实际中没怎么见到应用,那是因为你没有去仔细的观察,而且...

    帅地
  • PHP爬虫

    使用PHP Simple HTML DOM Parser这个库,然后自己对DOM选择器做一下二次封装,基本上可以应付一部分WordPress站点。

    libo1106
  • 数据结构之线段树

    1、什么是线段树(也称为区间树)Segment Tree。为什么使用线段树,线段树解决了什么问题,对于有一类问题,我们关心的是线段(或者区间)。

    别先生

扫码关注云+社区

领取腾讯云代金券