使用Python对json文件进行处理详解编程语言

本文主要介绍如何使用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() 

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/8234.html

(0)
上一篇 2021年7月18日 19:30
下一篇 2021年7月18日 19:30

相关推荐

发表回复

登录后才能评论