My JSON object looks something like this:
{
id: 1
object:
{
object_id:1
key_for_1: "value for object type 1"
}
type: "object_type_1"
}
{
id: 2
object:
{
object_id:5
key_for_23: "value for object type 23"
}
type: "object_type_23"
}
So, basically i need "type" before i can parse object. Is there a way to ensure that I can grab the value for "type" before i grab "object"?
JsonReader is has pretty much the same methods as GSON. Here is how I am parsing it:
public CustomObject(JsonReader reader) throws IOException {
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
if (name.equals("id")) {
clId = reader.nextDouble();
}
else if (name.equals("object")) {
innerObject = new InnerObject(reader);
}
else if (name.equals("type")) {
type = reader.nextString();
}
}
reader.endObject();
}
I don't want to just use a string builder because the actual JSON object I get back is HUGE (the one above is just a sample). I tried StringBuilder first and I am seeing quite a few out of memory problems which is why I wanted to move to JsonReader.
Any help would be awesome. Thanks