An error occurred while parsing the JSON file, possibly a hidden value in the JSON content

WBOY
Release: 2024-02-06 08:39:11
forward
1256 people have browsed it

解析 JSON 文件时出错,可能是 JSON 内容的隐藏值

Question content

I have this JSON file:

https://drive.google.com/file/d/1zh_fJJNWs9GaPnlLZ459twSubsYkzMi5/view?usp=share_link

Looks normal at first, even using the online json schema validator However, when parsing it locally, I get an error. I tried with python, nodejs and golang but it doesn't work. I think it might have some hidden value that makes it impossible to parse it


Correct answer


This is the complete solution. Comments added to the code.

# read the file as bytes
import chardet
import json
file_path=r"2022_2973.json"
with open (file_path , "rb") as f:
    data= f.read() # read file as bytes
file_encoding=chardet.detect(data)['encoding'] # detect the encoding
print(f"file(bytes) encoding:{file_encoding}") # print encoding

json_data = json.loads(data.decode(file_encoding)) # decode the bytes and load the json data
json_data['snaps'][1]
Copy after login

Output:

file(bytes) encoding:UTF-16
{'group': 'Slot',
 'group_order': 1,
 'positions': [{'group': 'Slot',
   'position': 'SLWR',
Copy after login

The above is the detailed content of An error occurred while parsing the JSON file, possibly a hidden value in the JSON content. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template