__author__ = "JentZhang"

 import json

 user_info = {"id": 1000, "name": "zhangsan", "age": 25, "address": "xxxxxxxxxx", "mobile": ""}

 # 将字典转换为JSON字符串
json_str = json.dumps(user_info)
print(json_str)
print(type(json_str)) # 将JSON字符串转换为字典
str_json = '{"name":"zhangsan","age":20}'
json_obj = json.loads(str_json)
print(json_obj)
print(type(json_obj)) f = open('json_file','w')
dic = {'k1':'v1','k2':'v2','k3':'v3'}
json.dump(dic,f) #dump方法接收一个文件句柄,直接将字典转换成json字符串写入文件
f.close() f = open('json_file')
dic2 = json.load(f) #load方法接收一个文件句柄,直接将文件中的json字符串转换成数据结构返回
f.close()
print(type(dic2),dic2)

python3中json模块的用法的更多相关文章

  1. python3中time模块的用法及说明

    python中,导入time模块使用的命令是 import time 可以使用以下命令查看time模块内置的能够使用的方法: dir(time) 可以使用以下命令查看time模块中每个内置方法的说明: ...

  2. Python3中正则模块re.compile、re.match及re.search函数用法详解

    Python3中正则模块re.compile.re.match及re.search函数用法 re模块 re.compile.re.match. re.search 正则匹配的时候,第一个字符是 r,表 ...

  3. python3.7 json模块

    #!/usr/bin/env python __author__ = "lrtao2010" #python3.7 json模块 ''' 要在不同的编程语言之间传递对象,就必须把对 ...

  4. python3 中mlpy模块安装 出现 failed with error code 1的决绝办法(其他模块也可用本方法)

    在python3 中安装其它模块时经常出现 failed with error code 1等状况,使的安装无法进行.而解决这个问题又非常麻烦. 接下来以mlpy为例,介绍一种解决此类安装问题的办法. ...

  5. Python3中使用Mysql的用法。

    一.Python2中一般使用MySqldb来调用Mysql,但是在Python3中不支持该包,使用pymysql来代替了,用法一模一样. 二.安装: pip install pymysql 三.例子: ...

  6. python3之json模块使用

    1. json模块介绍 json是python自带的操作json的模块. python序列化为json时的数据类型转换关系: python格式 json格式 dict(复合类型) object lis ...

  7. Python3中json的encode和decode

    在Python3中,将对象序列化为JSON对象,即对对象进行json encode编码,使用函数 json.dumps(obj, *, skipkeys=False, ensure_ascii=Tru ...

  8. Python3之json模块

    概念: 序列化(Serialization):将对象的状态信息转换为可以存储或可以通过网络传输的过程,传输的格式可以是JSON,XML等.反序列化就是从存储区域(JSON,XML)读取反序列化对象的状 ...

  9. python 导入json模块的用法

    json用于字符串,和 python数据类型间进行转换,json模块有四个功能,dumps,dump,loads,load. json 用法 json.dumps 将数据通过特殊的形式转换为所有程序语 ...

随机推荐

  1. MySQL 5.7 安装指南

    1.下载1)进⼊入官⽹网下载5.7.23压缩包 下载地址:https://dev.mysql.com/downloads/mysql /5.7.html#downloads 2.安装与配置 1)将下载 ...

  2. 手机touch事件及参数【转】(自己懒得写了,找了一篇摘过来)

    [html5构建触屏网站]之touch事件 前言 一个触屏网站到底和传统的pc端网站有什么区别呢,交互方式的改变首当其冲.例如我们常用的click事件,在触屏设备下是如此无力. 手机上的大部分交互都是 ...

  3. 企业IT管理员IE11升级指南【11】—— 通过SCCM 2012和WSUS部署Internet Explorer 11

    企业IT管理员IE11升级指南 系列: [1]—— Internet Explorer 11增强保护模式 (EPM) 介绍 [2]—— Internet Explorer 11 对Adobe Flas ...

  4. 【RL-TCPnet网络教程】第15章 RL-TCPnet之创建多个TCP连接

    第15章     RL-TCPnet之创建多个TCP连接 本章节为大家讲解RL-TCPnet的TCP多客户端实现,因为多客户端在实际项目中用到的地方还挺多,所以我们也专门开启一个章节做讲解.另外,学习 ...

  5. navicat实现Mysql数据备份

    方法/步骤     使用navicat工具连接mysql数据库,这里以navicat for Mysql工具为例.如果数据库在本机,那么连接ip处写localhost即可,如果数据库在其他机器,那需要 ...

  6. [Swift]LeetCode97. 交错字符串 | Interleaving String

    Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. Example 1: Input: s1 = ...

  7. [Swift]LeetCode502. IPO(首次公开募股) | Initial Public Offerings

    Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Cap ...

  8. [Swift]LeetCode876. 链表的中间结点 | Middle of the Linked List

    Given a non-empty, singly linked list with head node head, return a middle node of linked list. If t ...

  9. [Swift]LeetCode975. 奇偶跳 | Odd Even Jump

    You are given an integer array A.  From some starting index, you can make a series of jumps.  The (1 ...

  10. Shell获取时间,日期,上月,当月,下月

    #当前日期 $ date +%F #当前时间$ date +"%F %H:%M:%S" #昨日$ date -d yesterday +%F #上一个月 $ date -d &qu ...