json序列化

把内存的数据变成字符串

import json

import pickle

import json
import pickle


def sayhi(name):
    print ("hello!",name)

info1 ={
    'name':'Lucas',
    'age':10,
   #"func":sayhi
}
info = ["a","b","c"]
f = open("test","w")

#f.write(pickle.dumps(info))
f.write(json.dumps(info1))
f.close()
序列化
import json
import pickle

def sayhi(name):
    print ("hello!",name)

f = open("test","r")

#data = json.loads(f.read())
data = json.loads(f.read())
#print(data)
print(data["name"])
反序列化

 

参考文档:http://www.cnblogs.com/alex3714/articles/5161349.html

posted @ 2018-05-08 22:24  ywyin  阅读(98)  评论(0编辑  收藏  举报