Skip to content

Commit

Permalink
feat: reformat print error example and clarify v1.6.0 example
Browse files Browse the repository at this point in the history
  • Loading branch information
erin-liman-tiktok committed Nov 23, 2022
1 parent dda5da9 commit 49df6d3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions README.md
Expand Up @@ -190,21 +190,24 @@ import "github.com/bytedance/sonic/decoder"
var data interface{}
err := sonic.UnmarshalString("[[[}]]", &data)
if err != nil {
/*one line by default*/
/* One line by default */
println(e.Error()) // "Syntax error at index 3: invalid char\n\n\t[[[}]]\n\t...^..\n"
/*pretty print*/
/* Pretty print */
if e, ok := err.(decoder.SyntaxError); ok {
/*Syntax error at index 3: invalid char
[[[}]]
...^..
*/
print(e.Description())
}else if me, ok := err.(decoder.MismatchTypeError); ok {
print(e.Description()
} else if me, ok := err.(decoder.MismatchTypeError); ok {
// decoder.MismatchTypeError is new to Sonic v1.6.0
print(me.Description())
}
}
```

#### Mismatched Types [Sonic v1.6.0]
If there a **mismatch-typed** value for a given key, sonic will report `decoder.MismatchTypeError` (if there are many, report the last one), but still skip wrong the value and keep decoding next JSON.
```go
import "github.com/bytedance/sonic"
Expand Down

0 comments on commit 49df6d3

Please sign in to comment.