Created
October 14, 2021 13:46
-
-
Save linw1995/c5f022358894f91ddc5833ed683a535f to your computer and use it in GitHub Desktop.
json.Unmarshal can parse null into empty array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"encoding/json" | |
) | |
func main() { | |
var ( | |
lst []string | |
err error | |
) | |
err = json.Unmarshal(([]byte)("null"), &lst) | |
fmt.Println(lst, err) | |
err = json.Unmarshal(([]byte)("[]"), &lst) | |
fmt.Println(lst, err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment