zoukankan      html  css  js  c++  java
  • python json实例解析

    python和json

      python这个语言的流行程度不用我说了,估计大家都知道吧。在字符串处理领域,json真是神一样的存在。最近一个项目中用到了,才感觉到它的威力。感觉非常有必要做一个记录和总结。

     

    json是谁?

      JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,易于人阅读和编写。Json模块提供了四个功能:dumps、dump、loads、load

     

    实例解析

     下面一个简单的例子,解析了json的用法。

    import json
    
    test_dirct = {'bridge':"hello word",'lili':32,'horse':"yellow"}
    print(type(test_dirct))
    
    json_str = json.dumps(test_dirct)
    print(json_str)
    print(type(json_str))
    
    
    
    new_dict = json.loads(json_str)
    print(new_dict)
    print(type(new_dict))
    
    with open("file.json",'w') as f:
        json.dump(new_dict,f)
        print("json load success")
    
    
    with open("file.json",'r') as load_f:
        load_dict = json.load(load_f)
        print(load_dict)
  • 相关阅读:
    关于vue的一些总结
    mvc中html导出成word下载-简单粗暴方式
    获取ip地址及城市信息
    .net中html转pdf
    div+css布局的问题
    js面向对象总结
    ES5&&ES6
    前端问题总结
    在vue的项目中引入swiper插件
    vue脚手架的使用
  • 原文地址:https://www.cnblogs.com/dylancao/p/12696612.html
Copyright © 2011-2022 走看看