import xlwt
import os
import json
import jsonpath
def analyze_data ( data, result) :
if isinstance ( data, dict ) :
for k, v in data. items( ) :
analyze_data( v, result + ".%s" % str ( k) )
elif isinstance ( data, ( list , tuple ) ) :
for i in range ( len ( data) ) :
analyze_data( data[ i] , result + "[%s]" % i)
else :
print ( result + "=" + str ( data) )
def get_itemboy1 ( filepath) :
tmp = [ ]
file = open ( filepath, 'r' , encoding= 'utf-8' )
testread = file . readlines( )
first_line = testread[ 0 ]
if first_line. startswith( u'\ufeff' ) :
mydata = first_line. encode( 'utf8' ) [ 3 : ] . decode( 'utf8' )
file . close( )
testdata = json. dumps( mydata, indent= 4 , ensure_ascii= False )
testjson = json. loads( testdata)
print ( testjson)
print ( type ( testjson) )
bb = json. loads( testjson)
print ( bb[ 'args' ] )
print ( type ( bb) )
print ( '将jsons1解析后的结果如下:' )
analyze_data( bb, result= "myfile" )
return tmp
if __name__ == "__main__" :
get_itemboy1( 'C:\\Users\\31216\\Desktop\\testgo0.txt' )