感兴趣python解析json数据并导出成普通文本示例的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。
# 来自jb51.cc
# -*- encoding:utf-8 -*-
import json
import warnings
warnings.filterwarnings("ignore")
if __name__=="__main__":
import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )
if len(sys.argv)==1:
print "need argv"
else:
print sys.argv
for json_array in open('/home/spark/opt/Log_Data/Py_logproc/log_tmpdir/yemaopythonlog'):
yemao_array = json.loads(json_array)
for yemao in yemao_array:
if not yemao.has_key('_reason'):
time = yemao['time']
url_current = yemao['url_current']
phone = yemao['phone']
token = yemao['token']
f=open('/home/spark/opt/Log_Data/Py_logproc/log_tmpdir/xxxx.txt','a+')
f.write('%d'%time+'|'+url_current+'|'+phone+'|'+token+'\n')
f.close()
print 'yemao_array_insert_file done'