zoukankan      html  css  js  c++  java
  • Python字典的json格式化处理(换行与不换行)

    Prefer = {"jim": {"War": 1.9, "the big bang": 1.0, "The lord of wings": 4.0, "Beautiful America": 4.7}, "lily": {"War": 2.0, "Kongfu": 4.1, "The lord of wings": 3.6}, "tommy": {"War": 2.3, "Kongfu": 5.0, "The lord of wings": 3.0}, "jack": {"War": 2.8, "Kongfu": 5.5, "The lord of wings": 3.5}}
    print('将字典一行显示不换行')
    print(json.dumps(Prefer))
    print('将字典按照json样式可视化显示')
    print(json.dumps(Prefer,indent=1))
    

    显示的结果是:

     1 将字典一行显示不换行
     2 {"jim": {"War": 1.9, "the big bang": 1.0, "The lord of wings": 4.0, "Beautiful America": 4.7}, "lily": {"War": 2.0, "Kongfu": 4.1, "The lord of wings": 3.6}, "tommy": {"War": 2.3, "Kongfu": 5.0, "The lord of wings": 3.0}, "jack": {"War": 2.8, "Kongfu": 5.5, "The lord of wings": 3.5}}
     3 将字典按照json样式可视化显示
     4 {
     5  "jim": {
     6   "War": 1.9,
     7   "the big bang": 1.0,
     8   "The lord of wings": 4.0,
     9   "Beautiful America": 4.7
    10  },
    11  "lily": {
    12   "War": 2.0,
    13   "Kongfu": 4.1,
    14   "The lord of wings": 3.6
    15  },
    16  "tommy": {
    17   "War": 2.3,
    18   "Kongfu": 5.0,
    19   "The lord of wings": 3.0
    20  },
    21  "jack": {
    22   "War": 2.8,
    23   "Kongfu": 5.5,
    24   "The lord of wings": 3.5
    25  }
    26 }

  • 相关阅读:
    完整的WSDL语法
    WSDL UDDI
    八一八 The Social Network的小细节
    MySQL命令行常用命令
    AspectJ风格的Aop切点表达式
    强大的Mockito测试框架
    MySQL锁定状态查看命令
    Yum本地Rpm库设置
    Sed实例大全
    为何 Emacs 和 Vim 被称为两大神器
  • 原文地址:https://www.cnblogs.com/langqi250/p/10942616.html
Copyright © 2011-2022 走看看