programing

json.discloss.jisclos.jisclJSONDecode Error: 추가 데이터: 2행 1열(char 190)

fastcode 2023. 3. 11. 09:34
반응형

json.discloss.jisclos.jisclJSONDecode Error: 추가 데이터: 2행 1열(char 190)

다음 코드를 실행하고 있습니다.

import json

addrsfile = 
open("C:\\Users\file.json", 
"r")
addrJson = json.loads(addrsfile.read())
addrsfile.close()
if addrJson:
    print("yes")

하지만 나에게 다음 오류를 주는 건...

Traceback (most recent call last):
  File "C:/Users/Mayur/Documents/WebPython/Python_WebServices/test.py", line 9, in <module>
    addrJson = json.loads(addrsfile.read())
  File "C:\Users\Mayur\Anaconda3\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "C:\Users\Mayur\Anaconda3\lib\json\decoder.py", line 342, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 190)

누가 나 좀 도와줘요?

JSON 파일은...

{"name": "XYZ", "address": "54.7168,94.0215", "country_of_residence": "PQR", "countries": "LMN;PQRST", "date": "28-AUG-2008", "type": null}
{"name": "OLMS", "address": null, "country_of_residence": null, "countries": "Not identified;No", "date": "23-FEB-2017", "type": null}

json 파일에 두 개의 레코드가 있고json.loads()둘 이상의 디코딩을 할 수 없습니다.당신은 그것을 기록으로 해야 합니다.

Python json.loads에 ValueError: 추가 데이터가 표시됩니다.

또는 어레이를 포함하도록 json을 다시 포맷해야 합니다.

{
    "foo" : [
       {"name": "XYZ", "address": "54.7168,94.0215", "country_of_residence": "PQR", "countries": "LMN;PQRST", "date": "28-AUG-2008", "type": null},
       {"name": "OLMS", "address": null, "country_of_residence": null, "countries": "Not identified;No", "date": "23-FEB-2017", "type": null}
    ]
}

다시 받아들일 수 있을 거야그러나 여러 개의 최상위 개체가 있을 수 없습니다.

REST API 콜에서 JSON을 해석하다가 이 오류가 발생하였습니다.API가 "fussier"(파라미터 순서 등)가 되어 잘못된 결과를 반환하는 것으로 나타났습니다.기대하는 것을 얻을 수 있는지 확인합니다.

이 오류는 문자열에 다음과 같은 부분이 있는 경우에도 나타날 수 있습니다.json.loads()가 인식되지 않습니다.이 예의 문자열에서는 문자 27에서 오류가 발생합니다.(char 27).

string = """[{"Item1": "One", "Item2": False}, {"Item3": "Three"}]"""

이 문제에 대한 나의 해결책은string.replace()다음 항목을 문자열로 변환합니다.

import json

string = """[{"Item1": "One", "Item2": False}, {"Item3": "Three"}]"""

string = string.replace("False", '"False"')

dict_list = json.loads(string)

언급URL : https://stackoverflow.com/questions/48140858/json-decoder-jsondecodeerror-extra-data-line-2-column-1-char-190

반응형