I was wondering what is most efficient (not wasting memory) and fastest way to download a JSON file and parse it.
I looked into the json.Decoder but are they any other solutions out there?
Thanks in advance.
评论:
raff99:
dgryski:Assuming your JSON file is large because it contains long list of objects, you do something like this:
https://golang.org/pkg/encoding/json/#example_Decoder_Decode_stream
Basically you you find the beginning of the array using the streaming API and then use json.Decoder to decode the array elements one by one.
There are a number of third-party JSON decoders, with various trade-offs: https://github.com/pquerna/ffjson , https://github.com/mailru/easyjson , but I would benchmark first to determine that json.Decoder isn't performing well enough before switching to one of them.
