Created
September 13, 2015 08:55
-
-
Save julianshen/2416ee3dc15c7358340f to your computer and use it in GitHub Desktop.
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 ( | |
"encoding/json" | |
"fmt" | |
"os" | |
) | |
func main() { | |
type User struct { | |
ObjectId, SessionToken, Username string | |
} | |
fileReader, err := os.Open("_User.json") | |
if err != nil { | |
panic(err) | |
} | |
defer fileReader.Close() | |
dec := json.NewDecoder(fileReader) | |
// read open bracket | |
for { | |
t, err := dec.Token() | |
if err != nil { | |
panic(err) | |
} | |
d, ok := t.(json.Delim) | |
if ok && d.String() == "[" { | |
break | |
} | |
} | |
var m User | |
// while the array contains values | |
for dec.More() { | |
// decode an array value (User) | |
err := dec.Decode(&m) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("%v: %v: %v\n", m.ObjectId, m.Username, m.SessionToken) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment