the last key was I had seen and then I store the value in the appropriate variable. For the
example from before I would do
1
void ExampleListener::key(String key) {
2 currentKey_ = key;
3 }
4
5
void ExampleListener::value(String key) {
6
if (currentKey_ == "name") {
7
name_ = value;
8
} else if (currentKey_ == "city") {
9
city_ = value;
10 }
11 }
In the stream of the object {“name”: “Eichhorn”} we will first get a call to the method key() with
the value “name” which we store in currentKey_. Next the parser will detect a value and call
our value() method with the value “Eichhorn”. The parser can now make the connection (or
create a context) that after the key “name” the value “Eichhorn” should be stored in the
member variable name_.