zoukankan      html  css  js  c++  java
  • 励志写一篇有味道的博文------json

    之前有更古老的数据交互中间键xml,但是由于比较复杂后来出现了json

    json :轻量级数据交换格式

    json与python数据对比

    json        python

    object      dict

    array        list

    string        str

    number     int

    number    float

    false         false

    null          none

    --------------------------------------------------------楚河汉界----------------------------------------------------

    将json字符串转化为python数据格式(正反序列化)

    import json

    dict = {'name': 'zhangsan', 'age': 33, 'address': '红星路'}
    print('未序列化前的数据类型为:', type(dict))
    print('为序列化前的数据:', dict)
    # 对dict进行序列化的处理
    dict_xu = json.dumps(dict, ensure_ascii=False) # 添加ensure_ascii=False进行序列化
    print('序列化后的数据类型为:', type(dict_xu))
    print('序列化后的数据为:', json)
    # 对dict_xu进行反序列化处理
    dict_fan = json.loads(dict_xu)
    print('反序列化后的数据类型为:', type(dict_fan))
    print('反序列化后的数据为: ', dict)

    print (json.__all__) #查看json库的所有方法
  • 相关阅读:
    LeetCode18. 四数之和
    15. 三数之和
    LeetCode202. 快乐数
    LeetCode1. 两数之和
    LeetCode349. 两个数组的交集
    LeetCode242. 有效的字母异位词
    VSCode运行时弹出powershell
    关于cin, cin.get(), getchar(),getline()的字符问题
    剑指 Offer 27. 二叉树的镜像
    BFS zoj 1649
  • 原文地址:https://www.cnblogs.com/jum-bolg/p/10793841.html
Copyright © 2011-2022 走看看