Specific parameters adjusted according to the actual situation
1 #-*-coding:utf-8-*2 ImportJSON3 ImportXLWT4 ImportOS5 ImportSYS6 7 Reload (SYS)8Sys.setdefaultencoding ('Utf-8')9dir = OS.GETCWD (). Decode ('Utf-8')TenDirlist =Os.listdir (dir) One Printdirlist A - - defReadjson (): thes = [] - forFileinchdirlist: - if ". JSON" inchFile: -With open (file,'R') as FR:#To open a file with +data = Json.load (FR)#use the Load method in JSON to convert the JSON string into a dictionary -S.append (data)#Save all dictionaries to the list + returns A at - defWriteexcel (J): -Workbook = xlwt. Workbook (encoding='Utf-8') -Booksheet = Workbook.add_sheet ('Sheet', cell_overwrite_ok=True) -Rvalue =J - #Print Rvalue intitle = [] - forKvinchEnumerate (rvalue[0]): to Title.append (v) + booksheet.write (0, K, v) - Printtitle the * forAinchRange (len (rvalue)): $ forBinchRange (len (title)):Panax Notoginseng Try: -D =Title[b] thec =str (rvalue[a][d]) + #if C: ABooksheet.write (A + 1, B, c) the #Else: + #if c = = ': - #Booksheet.write (A + 1, B, ' {} ') $ #Else: $ #Booksheet.write (A + 1, B, ' {} ') - except: -Booksheet.write (A + 1, B,"') theWorkbook.save (U'Merge'+'. xls') - Wuyi the if __name__=='__main__': -QQQ = Json.dumps (Readjson () [0], encoding="UTF-8", ensure_ascii=False) WuWriteexcel (Readjson () [0])
JSON to Excel Python