本文主要介绍如何使用Python读取json文件并将内容编码为json格式,对于json数据的具体处理方法并没有介绍。
- #!/usr/bin/env python
- #-*- encoding: gbk -*-
- import string,time
- import json
- j_file=open("1.json","r")
- lines="a"
- while 1:
- lines = j_file.readline().strip("\n")
- if not lines:
- break
- j_list = eval(lines)#字符串变字典
- json_string = json.dumps(j_list)#进行json编码
- json_str = json.loads(json_string)
- #可在此对json_str进行任何操作
- j_file.close()
来源: http://www.phpxs.com/code/1004934/