V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
just1
V2EX  ›  程序员

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

  •  
  •   just1 · Jan 17, 2016 via Android · 1937 views
    This topic created in 3764 days ago, the information mentioned may be changed or developed.
    怎么实现类似命令行下 json.tool 的 pretty-print 一样的输出,最方便是用 json 格式化的 js ,不过不太想用。有轮子吗?
    example:
    ```
    {
    "json": "obj"
    }
    ```
    Supplement 1  ·  Jan 17, 2016
    a=json.dumps(data,indent=1)
    实现了
    chemzqm
        1
    chemzqm  
       Jan 17, 2016   ❤️ 1
    just1
        2
    just1  
    OP
       Jan 17, 2016 via Android
    @chemzqm 感谢,不过这和 python -mjson.tool 似乎是一样的,我的意思可能没表达清楚,是将 json 格式化输出在网页上, so 换行是<br>,缩进要用&nbsp;
    ethego
        3
    ethego  
       Jan 17, 2016   ❤️ 1
    @just1 这么简单的功能,正则匹配替换一下不就好了吗?
    oott123
        4
    oott123  
       Jan 17, 2016   ❤️ 1
    我觉得用样式实现这个需求比较好。
    你可以考虑用 <pre> 标签包围你的 json 代码。
    just1
        5
    just1  
    OP
       Jan 17, 2016 via Android
    @oott123 确实没想到,很好的实现,感谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5436 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 53ms · UTC 07:09 · PVG 15:09 · LAX 00:09 · JFK 03:09
    ♥ Do have faith in what you're doing.