JSON写入文件错误,额外数据:第1行第2347列(字符2346)

时间:2018-10-30 01:46:23

标签: python json

    import json
    import requests

    response = requests.get('SOME_LINK_THAT_IVE_REMOVED')

    try:
        response.raise_for_status()
    except requests.exceptions.HTTPError:
        pass

    #print (response.text)

    with open('stats.json', 'w') as output:
         json.dump(response.json(), output, indent = 4)                      

what it printed:
  

{“ sessionid”:“ F9269D5D-2B5C-432B-B8BC-34F87F790619”,“ game_clock_display”:“ 02:12.84”,“ game_clock”:132.8432,“ game_status”:“正在玩”,“拥有”:[0 ,2],“ teams”:[{“ players”:[{“ name”:“ Nooth”,“ playerid”:2,“ position”:[-8.6900005,-0.28800002,-8.6470003],“ stats”:{ “ possession_time”:22.589041,“积分”:0,“保存”:0,“目标”:0,“眩晕”:3,“通过”:0,“接球”:0,“偷”:0:“块“:0,”拦截“:0,”助手“:0,” shots_taken“:0},”用户ID“:658915067565875,”拥有“:false},{”名称“:” erikmelkumyan“,”玩家ID“:3 ,“ position”:[-0.72400004,1.7060001,-28.595001],“ stats”:{“ possession_time”:9.5638027,“ points”:0,“ saves”:0,“ goals”:0,“ stuns”:3, “ passes”:0,“ catches”:0,“ steals”:0,“ blocks”:0,“拦截”:0,“ assists”:0,“ shots_taken”:1},“ userid”:2126518170756015,“所有“:false},{” name“:” Sandman187 _“,” playerid“:4,” position“:[-2.3990002,2.3380001,-26.783001],” stats“:{” possession_time“:27.565685,” points“: 0,“ saves”:1,“ goals”:0,“ stuns”:4,“ passs”:0,“ catching”:0,“ steals”:0,“ blocks”:0,“ intercepts”:0, “ assists”:0,“ sho ts_taken“:1},” userid“:1611289978936588,” possession“:true}],” team“:” BLUE   TEAM“,” possession“:true,” stats“:{” points“:0,” possession_time“:59.718529,” intercepts“:0,” blocks“:0,” steals“:0,” catching“:0, “ passes”:0,“ saves”:1,“ goals”:0,“ stuns”:10,“ assists”:0,“ shots_taken”:2}},{“ players”:[{“ name”:“ MooneyWhy“,” playerid“:0,” position“:[-4.539,1.399,-13.481001],” stats“:{” possession_time“:14.364853,” points“:2,” saves“:1,” goals“: 0,“眩晕”:7,“通过”:0,“接球”:0,“偷”:1,“盖帽”:0,“拦截”:0,“助攻”:0,“射门得分”:1} ,“ userid”:1265147863612788,“ possession”:false},{“ name”:“ b-love”,“ playerid”:1,“ position”:[-11.484,2.072,0.70500004],“ stats”:{“ owner_time“:50.680099,”点数“:6,”保存“:1,”进球“:0,”眩晕“:1,”通过“:0,”接球“:0,”偷“:0:”阻拦“ :0,“拦截”:0,“助手”:0,“ shots_taken”:1},“用户ID”:1457786340976218,“拥有”:false},{“名称”:“ onikaze”,“玩家ID”:5, “ position”:[-7.6980004,1.268,-11.036],“ stats”:{“ possession_time”:17.629295,“ points”:0,“ saves”:0,“ goals”:0,“ stuns”:6,“通过“:0,”接球“:0,”偷“:0,”盖帽“:0,”拦截“:0,”助攻“:0, “ shots_taken”:2},“ userid”:1636331273057819,“ possession”:false}],“ team”:“ ORANGE   TEAM“,” possession“:false,” stats“:{” points“:8,” possession_time“:82.674248,” intercepts“:0,” blocks“:0,” steals“:1,” catching“:0, “ passes”:0,“ saves”:2,“ goals”:0,“ stuns”:14,“ assists”:0,“ shots_taken”:4}}]}

    Traceback (most recent call last):
      File "C:\Users\Kai\Desktop\Python\testv4.py", line 19, in <module>
        json.dump(response.json(), output, indent = 4)
      File "C:\Users\Kai\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\models.py",
     

第897行,在json中               返回complexjson.loads(self.text,** kwargs)             文件“ C:\ Users \ Kai \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ json__init __。py”,   负载中的第348行               返回_default_decoder.decode(s)             文件“ C:\ Users \ Kai \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ json \ decoder.py”,   第340行,处于解码状态               引发JSONDecodeError(“额外数据”,s,结束)           json.decoder.JSONDecodeError:额外数据:第1行第2347列(字符2346)

有帮助吗?似乎在文本文件中创建了无效的JSON文件。

在NotePad ++中查看时,在JSON文件的末尾创建NULL值

0 个答案:

没有答案