How can I read a "complex" json using Klaxon? I'm trying to use klaxon's stream api as documentation say .
I'm using the beginObject method. If I use a json as given in the example everything is fine
val objectString = """{
"name" : "Joe",
"age" : 23,
"flag" : true,
"array" : [1, 3],
"obj1" : { "a" : 1, "b" : 2 }
}"""
But if I try to parse a json with a nested object as the following example I get the following error: "Expected a name but got LEFT_BRACE"
val objectString = """{
"name" : "Joe",
"age" : 23,
"flag" : true,
"array" : [1, 3],
"obj1" : {
"hello": { "a" : 1, "b" : 2 }
}
}"""
I don't see any reported issues in the github repo, so I wonder if there is a way to get this working.
cheers
Ok so I checked out the source, and it seems that
nextObject()
assumes that you are dealing with a simple key value object, where values are not objects.Anyway, there is another way to parse a JSON of the format you specified, like below:
The classes I created are like below:
ABObj
represents this JSON:HelloObj
represents this JSON:And finally,
Obj
refers to the top level object.Hope this helps.