诗岑 2022-07-08 11:04 采纳率: 93%
浏览 337
已结题

demjson.JSONDecodeError: ('Unknown identifier', 'True')


import csv
import io
import numpy as np
from numpy.matlib import repmat
import demjson
import re
path=open('C:\\Users\\Administrator\\Desktop\\实训\\data\\beijing.txt','r',encoding='utf-8')
with open('C:\\Users\\Administrator\\Desktop\\实训\\data\\beijing.txt','r',encoding='utf-8')as f1:
    city_infos=f1.read()
filednames=['cityName','currentConfirmedCount', 'confirmedCount','suspectedCount','curedCount','deadCount','highDangerCount','midDangerCount','locationId','currentConfirmedCountStr']
city_dict=demjson.decode(city_infos)
with open('C:\\Users\\Administrator\\Desktop\\实训\\data\\beijing.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 11, 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: ('Unknown identifier', 'True')

文件内容:

[{'cityName': '朝阳区', 'currentConfirmedCount': 525, 'confirmedCount': 605, 'suspectedCount': 0, 'curedCount': 80, 'deadCount': 0, 'highDangerCount': 0, 'midDangerCount': 0, 'locationId': 110105, 'currentConfirmedCountStr': '525'}, {'cityName': '丰台区', 'currentConfirmedCount': 444, 'confirmedCount': 730, 'suspectedCount': 0, 'curedCount': 286, 'deadCount': 0, 'highDangerCount': 0, 'midDangerCount': 0, 'locationId': 110106, 'currentConfirmedCountStr': '444'}, {'cityName': '房山区', 'currentConfirmedCount': 314, 'confirmedCount': 334, 'suspectedCount': 0, 'curedCount': 20, 'deadCount': 0, 'highDangerCount': 0, 'midDangerCount': 0, 'locationId': 110111, 'notShowCurrentConfirmedCount': True, 'currentConfirmedCountStr': '-'}, {'cityName': '境外输入', 'currentConfirmedCount': 283, 'confirmedCount': 755, 'suspectedCount': 3, 'curedCount': 472, 'deadCount': 0, 'highDangerCount': 0, 'midDangerCount': 0, 'locationId': 0, 'currentConfirmedCountStr': '283'}, {'cityName': '海淀区', 'currentConfirmedCount': 276, 'confirmedCount': 358, 'suspectedCount': 0, 'curedCount': 82, 'deadCount': 0, 'highDangerCount': 0, 'midDangerCount': 0, 'locationId': 110108, 'currentConfirmedCountStr': '276'}, {'cityName': '通州区', 'currentConfirmedCount': 95, 'confirmedCount': 115, 'suspectedCount': 0, 'curedCount': 20, 'deadCount': 0, 'highDangerCount': 1, 'midDangerCount': 0, 'locationId': 110112, 'currentConfirmedCountStr': '95'}, {'cityName': '东城区', 'currentConfirmedCount': 64, 'confirmedCount': 83, 'suspectedCount': 0, 'curedCount': 19, 'deadCount': 0, 'highDangerCount': 0, 'midDangerCount': 0, 'locationId': 110101, 'currentConfirmedCountStr': '64'}, {'cityName': '昌平区', 'currentConfirmedCount': 62, 'confirmedCount': 112, 'suspectedCount': 0, 'curedCount': 50, 'deadCount': 0, 'highDangerCount': 1, 'midDangerCount': 1, 'locationId': 110114, 'notShowCurrentConfirmedCount': True, 'currentConfirmedCountStr': '-'}, {'cityName': '顺义区', 'currentConfirmedCount': 57, 'confirmedCount': 102, 'suspectedCount': 0, 'curedCount': 45, 'deadCount': 0, 'highDangerCount': 0, 'midDangerCount': 0, 'locationId': 110113, 'currentConfirmedCountStr': '57'}, {'cityName': '西城区', 'currentConfirmedCount': 56, 'confirmedCount': 115, 'suspectedCount': 0, 'curedCount': 59, 'deadCount': 0, 'highDangerCount': 0, 'midDangerCount': 0, 'locationId': 110102, 'currentConfirmedCountStr': '56'}, {'cityName': '大兴区', 'currentConfirmedCount': 34, 'confirmedCount': 168, 'suspectedCount': 0, 'curedCount': 134, 'deadCount': 0, 'highDangerCount': 0, 'midDangerCount': 0, 'locationId': 110115, 'notShowCurrentConfirmedCount': True, 'currentConfirmedCountStr': '-'}, {'cityName': '石景山区', 'currentConfirmedCount': 19, 'confirmedCount': 34, 'suspectedCount': 0, 'curedCount': 15, 'deadCount': 0, 'highDangerCount': 0, 'midDangerCount': 0, 'locationId': 110107, 'currentConfirmedCountStr': '19'}, {'cityName': '经济开发区', 'currentConfirmedCount': 14, 'confirmedCount': 14, 'suspectedCount': 0, 'curedCount': 0, 'deadCount': 0, 'highDangerCount': 0, 'midDangerCount': 0, 'locationId': 0, 'notShowCurrentConfirmedCount': True, 'currentConfirmedCountStr': '-'}, {'cityName': '门头沟区', 'currentConfirmedCount': 13, 'confirmedCount': 18, 'suspectedCount': 0, 'curedCount': 5, 'deadCount': 0, 'highDangerCount': 0, 'midDangerCount': 0, 'locationId': 110109, 'currentConfirmedCountStr': '13'}, {'cityName': '延庆区', 'currentConfirmedCount': 7, 'confirmedCount': 8, 'suspectedCount': 0, 'curedCount': 1, 'deadCount': 0, 'highDangerCount': 2, 'midDangerCount': 4, 'locationId': 110119, 'currentConfirmedCountStr': '7'}, {'cityName': '密云区', 'currentConfirmedCount': 3, 'confirmedCount': 10, 'suspectedCount': 0, 'curedCount': 7, 'deadCount': 0, 'highDangerCount': 0, 'midDangerCount': 0, 'locationId': 110118, 'notShowCurrentConfirmedCount': True, 'currentConfirmedCountStr': '-'}, {'cityName': '外地来京', 'currentConfirmedCount': 2, 'confirmedCount': 27, 'suspectedCount': 0, 'curedCount': 25, 'deadCount': 0, 'highDangerCount': 0, 'midDangerCount': 0, 'locationId': 0, 'notShowCurrentConfirmedCount': True, 'currentConfirmedCountStr': '-'}, {'cityName': '怀柔区', 'currentConfirmedCount': 1, 'confirmedCount': 9, 'suspectedCount': 0, 'curedCount': 8, 'deadCount': 0, 'highDangerCount': 0, 'midDangerCount': 0, 'locationId': 110116, 'notShowCurrentConfirmedCount': True, 'currentConfirmedCountStr': '-'}, {'cityName': '待明确地区', 'currentConfirmedCount': -2243, 'confirmedCount': 99, 'suspectedCount': 0, 'curedCount': 2333, 'deadCount': 9, 'highDangerCount': 0, 'midDangerCount': 0, 'locationId': -1, 'currentConfirmedCountStr': '-2243'}]

  • 写回答

1条回答 默认 最新

  • 崽崽的谷雨 2022-07-08 11:19
    关注

    json格式不规范吧 ,未知标识符

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 7月16日
  • 已采纳回答 7月8日
  • 创建了问题 7月8日

悬赏问题

  • ¥100 微信小程序跑脚本授权的问题
  • ¥100 房产抖音小程序苹果搜不到安卓可以付费悬赏
  • ¥15 STM32串口接收问题
  • ¥15 腾讯IOA系统怎么在文件夹里修改办公网络的连接
  • ¥15 filenotfounderror:文件是存在的,权限也给了,但还一直报错
  • ¥15 MATLAB和mosek的求解问题
  • ¥20 修改中兴光猫sn的时候提示失败
  • ¥15 java大作业爬取网页
  • ¥15 怎么获取欧易的btc永续合约和交割合约的5m级的历史数据用来回测套利策略?
  • ¥15 有没有办法利用libusb读取usb设备数据