Golang encoding/json.Decoder.Buffered() function example
package encoding/json
Buffered returns a reader of the data remaining in the Decoder's buffer. The reader is valid until the next call to Decode.
Golang encoding/json.Decoder.Buffered() function usage example
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"strings"
)
func main() {
reader := strings.NewReader(`{"Name" : "Adam"} extra string to be buffered`)
var m struct {
Name string
}
decoder := json.NewDecoder(reader)
err := decoder.Decode(&m)
if err != nil {
fmt.Println(err)
}
extraString, err := ioutil.ReadAll(decoder.Buffered()) // read the remainder
if err != nil {
fmt.Println(err)
}
fmt.Println(string(extraString))
}
Output :
extra string to be buffered
Reference :
Advertisement
Something interesting
Tutorials
+16.9k Golang : How to generate QR codes?
+18.6k Golang : Get download file size
+7.7k Golang : Command line ticker to show work in progress
+29.3k Golang : Save map/struct to JSON or XML file
+7.5k Golang : Process json data with Jason package
+14.6k Golang : Missing Bazaar command
+17.7k Golang : Read data from config file and assign to variables
+14.6k Golang : Convert(cast) int to float example
+31.9k Golang : Convert an image file to []byte
+9.6k Golang : Copy map(hash table) example
+11.3k Golang : Intercept and process UNIX signals example