V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
just1
V2EX  ›  程序员

web.py 实现 jsonpretty-print 的方法?

  •  
  •   just1 · 2016-01-17 17:09:35 +08:00 via Android · 1530 次点击
    这是一个创建于 3044 天前的主题,其中的信息可能已经有所发展或是发生改变。
    怎么实现类似命令行下 json.tool 的 pretty-print 一样的输出,最方便是用 json 格式化的 js ,不过不太想用。有轮子吗?
    example:
    ```
    {
    "json": "obj"
    }
    ```
    第 1 条附言  ·  2016-01-17 19:47:05 +08:00
    a=json.dumps(data,indent=1)
    实现了
    chemzqm
        1
    chemzqm  
       2016-01-17 17:30:48 +08:00   ❤️ 1
    just1
        2
    just1  
    OP
       2016-01-17 17:46:38 +08:00 via Android
    @chemzqm 感谢,不过这和 python -mjson.tool 似乎是一样的,我的意思可能没表达清楚,是将 json 格式化输出在网页上, so 换行是<br>,缩进要用&nbsp;
    ethego
        3
    ethego  
       2016-01-17 17:48:49 +08:00   ❤️ 1
    @just1 这么简单的功能,正则匹配替换一下不就好了吗?
    oott123
        4
    oott123  
       2016-01-17 18:02:56 +08:00   ❤️ 1
    我觉得用样式实现这个需求比较好。
    你可以考虑用 <pre> 标签包围你的 json 代码。
    just1
        5
    just1  
    OP
       2016-01-17 18:18:19 +08:00 via Android
    @oott123 确实没想到,很好的实现,感谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2264 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 07:56 · PVG 15:56 · LAX 00:56 · JFK 03:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.