fix: Invalid type for 'input[x].summary': expected an array of objects, but got null instead

This commit is contained in:
CaIon
2025-08-26 13:17:31 +08:00
parent a3c2b28d6a
commit e23f01f8d5
5 changed files with 73 additions and 28 deletions

View File

@@ -20,3 +20,25 @@ func DecodeJson(reader *bytes.Reader, v any) error {
func Marshal(v any) ([]byte, error) {
return json.Marshal(v)
}
func GetJsonType(data json.RawMessage) string {
data = bytes.TrimSpace(data)
if len(data) == 0 {
return "unknown"
}
firstChar := bytes.TrimSpace(data)[0]
switch firstChar {
case '{':
return "object"
case '[':
return "array"
case '"':
return "string"
case 't', 'f':
return "boolean"
case 'n':
return "null"
default:
return "number"
}
}