我有两种形式的相同 json 数据 - 一种是单行的,第二种只是格式化输出。JSON A:
{"id":1, "name":"BoxH", "readOnly":true, "children":[{ "id":100, "name":"Box1", "readOnly":true, "children":[ { "id":1003, "name":"Box2", "children":[ { "id":1019, "name":"BoxDet", "Ids":[ "ABC", "ABC2", "DEF2", "DEFHD", "LKK" ]}]}]}]}
和 JSON B:
{
"id":1,
"name":"BoxH",
"readOnly":true,
"children":[
{
"id":100,
"name":"Box1",
"readOnly":true,
"children":[
{
"id":1003,
"name":"Box2",
"children":[
{
"id":1019,
"name":"BoxDet",
"Ids":[
"ABC",
"ABC2",
"DEF2",
"DEFHD",
"LKK"
]
}
]
}
]
}
]
}
为什么会这样,代码:
import json
if open('input_file.json'):
output_json = json.load('input_file.json')
万一A抛出
ValueError: No JSON object could be decoded
并且案例 B 工作正常。我只是想知道为什么会这样?我认为 json.load 的 JSON A 和 JSON B 是相同的。我应该怎么做才能使这两种情况都起作用?