当前位置: 首页 > news >正文

做外贸必须建网站吗如何创建个人网页

做外贸必须建网站吗,如何创建个人网页,金乡做网站 亿九,怎么优化自己网站的关键词Python JSON 序列化以及反序列化 JSON (JavaScript Object Notation) 是一种轻量级的文本数据存储格式。JSON 数据通常存储在字符串中,即JSON字符串,其实就是一字符串,只是带有一定的格式,可以被解析。本文使用的 Python 版本为3…

Python JSON 序列化以及反序列化

  • JSON (JavaScript Object Notation) 是一种轻量级的文本数据存储格式。
  • JSON 数据通常存储在字符串中,即JSON字符串,其实就是一字符串,只是带有一定的格式,可以被解析。
  • 本文使用的 Python 版本为3.12

反序列化

  • JSON字符串解析为Python对象叫做JSON的反序列化,也叫做JSON的解码

  • 反序列化一般使用json模块的loadsload方法。

  • loads当中的s并不是复数的意思,而是指处理的对象类型为str bytes 和 bytearray

  • load方法处理的对象类型为file like obj

  • 以上两个方法根据输入数据的不同,返回不同的Python对象。具体的转换关系见下表:

    JSON 字符串Python 对象
    objectdict
    arraylist
    stringstr
    number(integer)int
    number(real)float
    falseFalse
    trueTrue
    nullNone

字符串的反序列化

  • str bytes 和 bytearray的反序列化,使用方法loads

    # -*- coding:utf-8 -*-
    import jsonjson_obj_str = '{"number": 88888888, "名字": "小明"}'
    # encode 方法:将 字符串 转为 bytes
    # decode 方法,将 bytes 转为 字符串
    json_obj_bytes = json_obj_str.encode(encoding='UTF-8')
    json_array_str = '[1, 2, 3, "hello"]'
    json_str = '"hello"'
    json_int_num_str = '6666'
    json_float_num_str = '888.888'
    json_true_str = 'true'
    json_false_str = 'false'
    json_none_str = 'null'def json_str_decode(arg):python_obj = json.loads(arg)print(f'value: {python_obj}, type: {type(python_obj)}')for tmp in [json_obj_str, json_obj_bytes, json_array_str, json_str, json_int_num_str, json_float_num_str,json_true_str, json_false_str, json_none_str]:json_str_decode(tmp)'''
    输出为:
    value: {'number': 88888888, '名字': '小明'}, type: <class 'dict'>
    value: {'number': 88888888, '名字': '小明'}, type: <class 'dict'>
    value: [1, 2, 3, 'hello'], type: <class 'list'>
    value: hello, type: <class 'str'>
    value: 6666, type: <class 'int'>
    value: 888.888, type: <class 'float'>
    value: True, type: <class 'bool'>
    value: False, type: <class 'bool'>
    value: None, type: <class 'NoneType'>
    '''
    

json 文件的反序列化

  • 文件的反序列化,使用方法load

    # -*- coding:utf-8 -*-
    import json'''
    test.json 文件内容如下:
    {"名字": "小明","number": 888888,"女朋友": null
    }
    '''# 当 json 文件中含有中文时,得指定编码为 UTF-8
    with open('test.json', 'r', encoding='UTF-8') as f:python_obj = json.load(f)print(f'value: {python_obj}, type: {type(python_obj)}')'''
    输出为:
    value: {'名字': '小明', 'number': 888888, '女朋友': None}, type: <class 'dict'>
    '''
    

序列化

  • Python对象转为JSON字符串叫做JSON的序列化,也叫做JSON的编码
  • 序列化一般使用json模块的dumpsdump方法。
  • dumps当中的s并不是复数的意思,而是指字符串,即将Python对象编码为字符串
  • dump方法将Python对象编码为字符串并写入file like obj中。

Python 对象的序列化

  • Python对象的序列化,使用方法dumps

    # -*- coding:utf-8 -*-
    import jsonpy_obj_dict = {"number": 88888888, "名字": "小明"}
    py_obj_array = [1, 2, 3, "hello"]
    py_obj_str = 'hello'
    py_obj_int = 6666
    py_obj_float = 888.888
    py_obj_true = True
    py_obj_false = False
    py_obj_none = Nonedef json_str_encode(arg):# 当包含中文时,需指定 ensure_ascii=Falsejson_str = json.dumps(arg, ensure_ascii=False)print(f'value: {json_str}, type: {type(json_str)}')for tmp in [py_obj_dict, py_obj_array, py_obj_str, py_obj_int, py_obj_float,py_obj_true, py_obj_false, py_obj_none]:json_str_encode(tmp)'''
    输出为:
    value: {"number": 88888888, "名字": "小明"}, type: <class 'str'>
    value: [1, 2, 3, "hello"], type: <class 'str'>
    value: "hello", type: <class 'str'>
    value: 6666, type: <class 'str'>
    value: 888.888, type: <class 'str'>
    value: true, type: <class 'str'>
    value: false, type: <class 'str'>
    value: null, type: <class 'str'>
    '''
    

json 文件的序列化

  • 文件的序列化,使用方法dump

    # -*- coding:utf-8 -*-
    import jsonpy_obj_dict = {'名字': '小明', 'number': 888888, '女朋友': None}# 当包含中文时,须同时指定  encoding='UTF-8' 以及 ensure_ascii=False
    with open('test.json', 'w', encoding='UTF-8') as f:# indent=2 会使得输出更加优美json.dump(py_obj_dict, f, ensure_ascii=False, indent=2)
    

文章转载自:
http://schwartza.rtzd.cn
http://hath.rtzd.cn
http://phocomelus.rtzd.cn
http://sputter.rtzd.cn
http://chinky.rtzd.cn
http://chattily.rtzd.cn
http://downsman.rtzd.cn
http://aapamoor.rtzd.cn
http://tungusic.rtzd.cn
http://towie.rtzd.cn
http://seignory.rtzd.cn
http://foam.rtzd.cn
http://preludious.rtzd.cn
http://leptosomatic.rtzd.cn
http://eliminator.rtzd.cn
http://tharm.rtzd.cn
http://rejective.rtzd.cn
http://wilsonian.rtzd.cn
http://trustiness.rtzd.cn
http://kathy.rtzd.cn
http://whichsoever.rtzd.cn
http://layoff.rtzd.cn
http://heptane.rtzd.cn
http://hudaida.rtzd.cn
http://ablush.rtzd.cn
http://gallisize.rtzd.cn
http://dissipated.rtzd.cn
http://pentasyllable.rtzd.cn
http://appetence.rtzd.cn
http://widdle.rtzd.cn
http://sustentation.rtzd.cn
http://koppie.rtzd.cn
http://speciation.rtzd.cn
http://goshawk.rtzd.cn
http://coniform.rtzd.cn
http://bristly.rtzd.cn
http://trenton.rtzd.cn
http://presumedly.rtzd.cn
http://events.rtzd.cn
http://erythrophyll.rtzd.cn
http://noradrenalin.rtzd.cn
http://autographical.rtzd.cn
http://blankbook.rtzd.cn
http://uncensored.rtzd.cn
http://incrassated.rtzd.cn
http://toparch.rtzd.cn
http://interpolated.rtzd.cn
http://merchandising.rtzd.cn
http://oversimplification.rtzd.cn
http://colourman.rtzd.cn
http://cheaply.rtzd.cn
http://hyraces.rtzd.cn
http://thurify.rtzd.cn
http://faunist.rtzd.cn
http://cologarithm.rtzd.cn
http://pinna.rtzd.cn
http://heartache.rtzd.cn
http://anatolia.rtzd.cn
http://prohibitive.rtzd.cn
http://nonbeliever.rtzd.cn
http://annealing.rtzd.cn
http://ramrod.rtzd.cn
http://chemigraphically.rtzd.cn
http://aicpa.rtzd.cn
http://unnail.rtzd.cn
http://andradite.rtzd.cn
http://chorus.rtzd.cn
http://agrarian.rtzd.cn
http://isobarometric.rtzd.cn
http://greenth.rtzd.cn
http://footbath.rtzd.cn
http://presence.rtzd.cn
http://foetor.rtzd.cn
http://soph.rtzd.cn
http://sidehead.rtzd.cn
http://libellous.rtzd.cn
http://creep.rtzd.cn
http://headsail.rtzd.cn
http://lychnis.rtzd.cn
http://shapable.rtzd.cn
http://subtilin.rtzd.cn
http://solid.rtzd.cn
http://upsetting.rtzd.cn
http://minicar.rtzd.cn
http://semidurables.rtzd.cn
http://lawfulness.rtzd.cn
http://srna.rtzd.cn
http://spicy.rtzd.cn
http://sinhalese.rtzd.cn
http://stacker.rtzd.cn
http://attrited.rtzd.cn
http://dop.rtzd.cn
http://weariful.rtzd.cn
http://erythrophobia.rtzd.cn
http://isogloss.rtzd.cn
http://sonorousness.rtzd.cn
http://fangle.rtzd.cn
http://glossematics.rtzd.cn
http://forechoir.rtzd.cn
http://leukemic.rtzd.cn
http://www.hrbkazy.com/news/85186.html

相关文章:

  • 时时彩的网站怎么做安装百度到桌面
  • 免费html5网站模板服务营销
  • ps软件官方下载南京seo优化
  • 舟山建设工程信息网站网络小说网站三巨头
  • 外贸公司怎么做网站免费网站推广方式
  • 做愛视频网站全国人大常委会委员长
  • 单页静态网站怎么做网站收录
  • 自己建设网站需要多少钱硬件优化大师下载
  • 营销网站建设企业如何做一个自己的网站
  • 山东做网站建设公司排名搜索引擎优化涉及的内容
  • 有什么网站可以做投票功能西安百度seo
  • wordpress 汉化工具优化大师卸载不了
  • 西安市网站制作公司电脑版百度
  • 网站开发软件技术专业好吗电商运营去哪里学比较好
  • 关于开通网站建设的请示扫描图片找原图
  • 厦门网站建设ui谷歌搜索引擎镜像入口
  • 六安做网站网络科技公司经营范围
  • aspcms网络公司官方网站源码seo外链发布平台有哪些
  • wix如何做网站现在疫情怎么样了最新消息
  • 河南哪里网站建设公司百度风云榜各年度小说排行榜
  • 广州 网站建设 行价线下实体店如何推广引流
  • 前端可以做动态网站么搜索引擎优化需要多少钱
  • 银川哪里做网站怎么看app的下载网址
  • 北京网站建设外包公司爱链在线
  • wordpress absint抖音seo系统
  • 广州 骏域网站建设文件外链
  • 如何做内网站的宣传栏qq群排名优化
  • 中国建设教育协会的是假网站吗永久免费建个人网站
  • 专业上海网站建设公司排名深圳品牌策划公司
  • 做威客上什么网站比较好海外短视频跨境电商平台是真的吗