import csv
import io
import numpy as np
from numpy.matlib import repmat
import demjson
import re
import sys
path=open('C:\\Users\\Administrator\\Desktop\\实训\\citydetail.txt','r',encoding='utf-8',errors='ignore')
with open('C:\\Users\\Administrator\\Desktop\\实训\\citydetail.txt','r',encoding='utf-8',errors='ignore')as f1:
city_infos=f1.read()
city_infos=city_infos.replace("'notShowCurrentConfirmedCount': True, ",'')
city_infos=city_infos.replace(" ",",")
city_infos=city_infos.replace(",",",")
filednames=['cityName','currentConfirmedCount', 'confirmedCount','suspectedCount','curedCount','deadCount','highDangerCount','midDangerCount','locationId','currentConfirmedCountStr']
city_dict=demjson.decode(city_infos)
with open('C:\\Users\\Administrator\\Desktop\\实训\\citydetail_new.csv','w',newline='',encoding='utf-8')as f2:
writer=csv.DictWriter(f2,filednames)
writer.writeheader()
writer.writerows(city_dict)
print("success")
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\实训\txttocsv.py", line 15, in <module>
city_dict=demjson.decode(city_infos)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\demjson.py", line 5696, in decode
result = j.decode( txt,
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\demjson.py", line 4915, in decode
raise errors[0]
demjson.JSONDecodeError: Can not decode value starting with character ','