zoukankan      html  css  js  c++  java
  • json 模块

    pickle 和  shevle  序列化后得到的数据只有python才能够解析

    通常企业开发不可能做一个单机程序 都需要联网进行计算机间的交互

    我们必须保证这个数据能够跨平台使用

      JSON是什么?   java scrip object  notation

      var obj  =  {"name" :"egon"}

      对于我们开发而言  json 就是一种通用的数据格式   任何语言都能解析

     js 中的数据类型         python数据类型  的对应关系

        {}                             字典

        []        列表

      string  “ ”                          str

      int/float                            int/float

      true/false       True/False

         null                                 None

      

      json 格式的语法规范

      最外层通常是一个字典或列表

      {}    or   []

      只要你想写一个json格式的数据  那么最外层直接写{}

      字符串必须是双引号

      你可以在里面套人一多的层次

      json模块的核心功能

      dump

      dumps

      load

      loads

      不带s  封装write    和read

    import json

    # 反序列化
    # with open("a.json","rt",encoding="utf-8") as f:
    # res = json.loads(f.read())
    # print(type(res))

    # with open("a.json",encoding="utf-8") as f:
    # print(json.load(f))


    # 直接解析字符串的json为python对象

    jsontext = """{
    "users": [{
    "name": "agon",
    "age": 68
    },
    {
    "name": "agon",
    "age": 68
    }
    ]
    }"""

    # res = json.loads(jsontext)
    # print(res)


    mydic = {
    "users": [{
    "name": "agon",
    "age": 68
    },
    {
    "name": "agon",
    "age": 68
    }
    ]
    }
    # with open("b.json","wt",encoding="utf-8") as f:
    # f.write(json.dumps(mydic))

    # with open("b.json", "wt", encoding="utf-8") as f:
    # json.dump(mydic, f)

    import json

    # dic = {"a": '理查德姑妈', "b": "找到你", "c": "看不见的客人"}
    # with open("c.json","wt",encoding="utf-8") as f:
    # f.write(json.dumps(dic))
    # print(repr(s), type(s))

    # with open("c.json","rt",encoding="utf-8") as f:
    # # print(f.read())
    # d = json.loads(f.read())
    # print(d)

     

  • 相关阅读:
    angular typescript 引入js文件
    (转)WEB页面导出为Word文档后分页&横向打印的方法
    aspx页面,后端通过Attributes.Add给textbox添加事件时,传参失效问题。
    aspx.designer.cs没有自动生成代码(没有自动注册)
    .net core 在CentOS环境下将微信公众号语音文件amr转化成mp3
    Sign in with Apple 后端验证(C#)
    C# 调用腾讯即时通信 IM
    LINQ入门笔记----LINQ To Object<Take(),TakeWhile(),Skip(),SkipWhile()>
    LINQ入门笔记----LINQ To Object<SelectMany()>
    初识LINQ
  • 原文地址:https://www.cnblogs.com/frank007/p/9806845.html
Copyright © 2011-2022 走看看