首页 > 后端开发 > Golang > 正文

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

WBOY
发布: 2024-02-06 08:39:11
转载
1396人浏览过

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

问题内容

我有这个 JSON 文件:

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

一开始看起来很正常,即使使用在线 json 模式验证器 但是,当在本地解析它时,我收到错误。 我用 python、nodejs 和 golang 尝试过,但它不起作用。 我认为它可能有一些隐藏的价值,使得无法解析它


正确答案


这是完整的解决方案。针对代码添加的注释。

Find JSON Path Online
Find JSON Path Online

Easily find JSON paths within JSON objects using our intuitive Json Path Finder

Find JSON Path Online 30
查看详情 Find JSON Path Online
# 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]
登录后复制

输出:

file(bytes) encoding:UTF-16
{'group': 'Slot',
 'group_order': 1,
 'positions': [{'group': 'Slot',
   'position': 'SLWR',
登录后复制

以上就是解析 JSON 文件时出错,可能是 JSON 内容的隐藏值的详细内容,更多请关注php中文网其它相关文章!

相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:stackoverflow网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门推荐
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号