1. 程式人生 > >python 基礎 7.8 json--下

python 基礎 7.8 json--下

utf usr 是把 轉換成 import pre 文件中 pri txt

一. 文件和json 之間的轉換 1. json.dump() #/usr/bin/python #coding=utf-8 #@Time :2017/11/13 0:12 #@Auther :liuzhenchuan #@File :json -下.py ##文件相關的 #load 肯定是從文件中摘出json 數據,load 肯定是把文件轉換成json數據 #dump 就是爸json 數據寫入到文件中。 # 示例1:把json 寫入到文件中 import json jsondate = {‘a‘:1,‘b‘:2.,‘c‘:3,‘d‘:4} with open(‘a.txt‘,‘w+‘) as fd:
json.dump(jsondate,fd) #示例:把文件用json格式讀出來 with open(‘a.txt‘,‘r‘) as fd1: m = json.load(fd1) print m print type(m)

python 基礎 7.8 json--下