博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
json 模块
阅读量:4635 次
发布时间:2019-06-09

本文共 1590 字,大约阅读时间需要 5 分钟。

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)

 

转载于:https://www.cnblogs.com/frank007/p/9806845.html

你可能感兴趣的文章
set 和select 的区别
查看>>
tableview或scrollview Y轴发生变化解决方案
查看>>
448. Find All Numbers Disappeared in an Array 寻找有界数组[1,n]中的缺失数
查看>>
七个帮助你处理Web页面层布局的jQuery插件
查看>>
学习笔记:AC自动机
查看>>
Java:JDK安装
查看>>
Java 7 中 NIO.2 的使用——第四节 文件和目录
查看>>
Class 泛型
查看>>
ASP.NET MVC5 ModelBinder
查看>>
Jzoj4348 打击目标
查看>>
day10-列表生成式
查看>>
Scrum meeting报告
查看>>
网络上常用的一些网站
查看>>
Android NDK MediaCodec在ijkplayer中的实践
查看>>
开始把其他的博客搬家到这里了
查看>>
计算机中整数加法满足结合律吗
查看>>
Unix基本系统数据类型和stat结构体
查看>>
Java JVM、JNI、Native Function Interface、Create New Process Native Function API Analysis
查看>>
FileStream功能被禁用
查看>>
MVC 中Simditor上传本地图片
查看>>