mirror of
https://github.com/ii64/sonic.git
synced 2026-06-21 00:46:43 +08:00
doc: print syntax error
This commit is contained in:
parent
4937f48f3c
commit
12dd7fb4a6
1 changed files with 25 additions and 0 deletions
25
README.md
25
README.md
|
|
@ -130,6 +130,31 @@ fn := root.Float64()
|
|||
fm := root.Interface().(float64) // jn == jm
|
||||
```
|
||||
|
||||
### Print Syntax Error
|
||||
```go
|
||||
import "github.com/bytedance/sonic/decoder"
|
||||
|
||||
var data interface{}
|
||||
dc := decoder.NewDecoder("[[[}]]")
|
||||
if err := dc.Decode(&data); err != nil {
|
||||
if e, ok := err.(decoder.SyntaxError); ok {
|
||||
|
||||
/*Syntax error at index 3: invalid char
|
||||
|
||||
[[[}]]
|
||||
...^..
|
||||
*/
|
||||
print(e.Description())
|
||||
|
||||
/*"Syntax error at index 3: invalid char\n\n\t[[[}]]\n\t...^..\n"*/
|
||||
println(fmt.Sprintf("%q", self.Description()))
|
||||
}
|
||||
|
||||
/*Decode: Syntax error at index 3: invalid char*/
|
||||
t.Fatalf("Decode: %v", err)
|
||||
}
|
||||
```
|
||||
|
||||
## Tips
|
||||
|
||||
### Pretouch
|
||||
|
|
|
|||
Loading…
Reference in a new issue