问题

{
“ClassificationSystem” : [
{
“CName” : “背景值”,
“Code” : “0”,
“Color” : “0,0,0”,
“EName” : “nodata”
},
{
“CName” : “旱地”,
“Code” : “12”,
“Color” : “255,215,0”,
“EName” : “dry farm”
}
]
}
{
“ClassificationSystem” : [
{
“CName” : “背景值”,
“Code” : “0”,
“Color” : “0,0,0”,
“EName” : “nodata”
},
{
“CName” : “旱地”,
“Code” : “12”,
“Color” : “255,215,0”,
“EName” : “dry farm”
}
]
}
里面有两个相同的"ClassificationSystem",只要一个

使用 json.JSONDecoder 手动解析

1
2
3
4
5
6
7
import json

with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
decoder = json.JSONDecoder()
# 只解析第一个 JSON 对象
data, idx = decoder.raw_decode(content)