I'm looking to use a a streaming json parser in an Android app, and I am wondering whether to use gson or the android.util.jsonreader library. Supposing that licensing and version compatibility are not a problem, which should I prefer given that:
In streaming mode, every JSON data is considered an individual token. When we use JsonReader to process it, each token will be processed sequentially. For example, While parsing with JsonReader, above JSON will generate 4 tokens:
How to create GSON JsonReader We can create a JsonReader instance using it’s simple constructor which accepts java.io.Reader type input stream. We can use one of following readers based on source of JSON stream:
JsonReader The JsonReader is the streaming JSON parser and an example of pull parser. It helps in reading a JSON (RFC 7159) encoded value as a stream of tokens. It reads both literal values (strings, numbers, booleans, and nulls) as well as the begin and end delimiters of objects and arrays.
It reads both literal values (strings, numbers, booleans, and nulls) as well as the begin and end delimiters of objects and arrays. The tokens are traversed in depth-first order, the same order that they appear in the JSON document. 2. Tokens In streaming mode, every JSON data is considered an individual token.
It doesn't much matter: android.util.JsonReader and com.google.gson.stream.JsonReader are the same code. The two classes have the same API and the same behavior.
That said, there are some tiny differences:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With