(새 문서: ==개요== ;Go isJSONString() <syntaxhighlight lang='go'> package main import ( "encoding/json" "fmt" ) func isJSONString(s string) bool { var js interface{} err := json.Unmars...) |
|||
1번째 줄: | 1번째 줄: | ||
==개요== | ==개요== | ||
;Go | ;Go json.Valid() | ||
<syntaxhighlight lang='go'> | <syntaxhighlight lang='go'> | ||
9번째 줄: | 9번째 줄: | ||
"fmt" | "fmt" | ||
) | ) | ||
func main() { | func main() { | ||
goodJSON := `{"example": 1}` | |||
badJSON := `{"example":2:]}}` | |||
fmt.Println(json.Valid([]byte(goodJSON))) // true | |||
fmt.Println(json.Valid([]byte(badJSON))) // false | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
2025년 2월 18일 (화) 16:34 판
1 개요
- Go json.Valid()
Go
Copy
package main
import (
"encoding/json"
"fmt"
)
func main() {
goodJSON := `{"example": 1}`
badJSON := `{"example":2:]}}`
fmt.Println(json.Valid([]byte(goodJSON))) // true
fmt.Println(json.Valid([]byte(badJSON))) // false
}
2 같이 보기
편집자 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.