Golang encoding/json.SyntaxError type and function example
package encoding/json
A SyntaxError is a description of a JSON syntax error.
Golang encoding/json.SyntaxError type and function usage example
if err != nil {
switch err.(type) {
case *json.SyntaxError, *json.InvalidUTF8Error: // <--- here
fmt.Printf("invalid json response: %s\n", err)
default:
fmt.Printf("Error: %s\n", err)
}
Reference :
Advertisement
Something interesting
Tutorials
+10.1k Golang : Compare files modify date example
+14.2k Golang : Convert IP version 6 address to integer or decimal number
+8.6k Android Studio : Import third-party library or package into Gradle Scripts
+4.4k Linux/MacOSX : Search and delete files by extension
+10.6k Fix ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)
+15.3k Golang : Get all local users and print out their home directory, description and group id
+15.9k Golang : Update database with GORM example
+22.1k Golang : Repeat a character by multiple of x factor
+39k Golang : How to iterate over a []string(array)
+23.9k Golang : Use regular expression to validate domain name
+17.1k Golang : Capture stdout of a child process and act according to the result