zoukankan      html  css  js  c++  java
  • python 字符与字节 json序列和反序列及支持的类型

    b = b"demo" 
    
    s = "demo"
    
    # 字符串转字节
    s = bytes(s, encoding = "utf8")
    
    s = str.encode(s)
    
    # 字节转字符串 
    s = str(b, encoding = "utf8")
    
    s = bytes.decode(b)

    json 序列与反序列化

    '''
    Supports the following objects and types by default:
    python支持的Json类型 +-------------------+---------------+ | Python | JSON | +===================+===============+ | dict | object | {} +-------------------+---------------+ | list, tuple | array |[]() +-------------------+---------------+ | str | string |"" +-------------------+---------------+ | int, float | number |124 +-------------------+---------------+ | True | true | +-------------------+---------------+ | False | false | +-------------------+---------------+ | None | null | +-------------------+---------------+ '''
    name = {'name': "gggg"}
    name01 = """{"name": "gggg"}"""
    # 转化成字符串(序列化)
    name_dumps = json.dumps(name)
    # 转化成json格式(反序列化)
    name01_loads = json.loads(name01)
    
    # json.dumps 序列化时对中文默认使用的ascii编码.想输出真正的中文需要指定ensure_ascii=False:
    print(type(name_dumps)) print(type(name01_loads))

    js中处理json

    序列化:
      Json.stringify()
    反序列化
    Json.parse()
  • 相关阅读:
    树状数组
    Windows系统重装
    桶排序
    PCL+VS2010环境配置
    刷题
    杭电ACM——自我强化步骤
    杭电ACM题单
    centos7 ifconifg没有ip
    centos7切换图像界面和dos界面
    oracle with as 的用法
  • 原文地址:https://www.cnblogs.com/ls1997/p/10892653.html
Copyright © 2011-2022 走看看