From 01c0d361944ba4479f6004d117310444434cab4c Mon Sep 17 00:00:00 2001 From: erin liman Date: Fri, 9 Dec 2022 01:00:49 -0800 Subject: [PATCH] feat: reformat print error example and clarify v1.6.0 example (#332) --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 554150a7c..5225911f0 100644 --- a/README.md +++ b/README.md @@ -190,9 +190,9 @@ 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 @@ -200,11 +200,14 @@ if err != nil { ...^.. */ 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"