使用Python對json文件進行處理
本文主要介紹如何使用Python讀取json文件并將內容編碼為json格式,對于json數據的具體處理方法并沒有介紹。
#!/usr/bin/env python-- encoding: gbk --
import string,time
import jsonj_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() </pre>
本文由用戶 cdfd 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!