forked from ricardolonga/jsongo
-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
package main
import (
j "github.com/libujacob/jsone"
)
func main() {
jsdoc := `{"number" : -1}`
j.ParseJsonObject([]byte(jsdoc))
}
Results in
2021/04/23 12:33:19 Invalid numeric value [-1]!
panic: Invalid numeric value [-1]!
Internal json lib json.Valid or json.Unmarshall works.
Maybe use something like this:
func isNumericValue(s string) bool {
if _, err := strconv.Atoi(s); err == nil {
return true
}
containsDot := 0
var negativeNumber bool
for i, ch := range s {
if ch == '.' {
containsDot++
} else if i == 0 && ch == '-' {
if len(s) > 1 {
negativeNumber = true
}
} else if ch < '0' || ch > '9' {
return false
}
}
if negativeNumber {
return negativeNumber && (containsDot == 0 || containsDot == 1)
}
return containsDot == 0 || containsDot == 1
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels