修复数组未判断长度导致索引越界的BUG

This commit is contained in:
白茶清欢 2025-04-29 11:37:13 +08:00
parent 7e464374bb
commit d139b409fd

View File

@ -106,6 +106,11 @@ func (oj *ownJson) generateStructField(rootPath string, currentName string, curr
if currentResult.IsArray() { if currentResult.IsArray() {
// 数组, 递归处理 // 数组, 递归处理
arrList := currentResult.Array() arrList := currentResult.Array()
if len(arrList) == 0 {
// 空数组,无法判断类型,使用any
oj.structBuilder.AddField(structPath, "", []any{}, "", false)
return
}
if arrList[0].Type == gjson.True || arrList[0].Type == gjson.False { if arrList[0].Type == gjson.True || arrList[0].Type == gjson.False {
oj.structBuilder.AddField(structPath, "", []bool{}, "", false) oj.structBuilder.AddField(structPath, "", []bool{}, "", false)
return return