Parses the specified json_text and emits parser events to the listener.
        If root_is_array then the root element of the json has to be an array/list,
        otherwise the expected root is a json object/dict.

        In case of python2 the json_text can be either an utf8 encoded string
        or a unicode object and the fired parser events will use the same format.

def parse(self, json_text, listener):
        """
        Parses the specified json_text and emits parser events to the listener.
        If root_is_array then the root element of the json has to be an array/list,
        otherwise the expected root is a json object/dict.

        In case of python2 the json_text can be either an utf8 encoded string
        or a unicode object and the fired parser events will use the same format.
        """
        listener.begin_parsing(self)
        try:
            self.init_text_parser(json_text)
            self.listener = listener

            c = self._skip_spaces_and_peek()
            if c == '{':
                if self.params.root_is_array:
                    self.error('The root of the json is expected to be an array!')
                self._parse_object()
            elif c == '[':
                if not self.params.root_is_array:
                    self.error('The root of the json is expected to be an object!')
                self._parse_array()
            else:
                self.error('The json string should start with "%s"' % (
                    '[' if self.params.root_is_array else '{'))

            if self._skip_spaces_and_peek() is not None:
                self.error('Garbage detected after the parsed json!')
        finally:
            listener.end_parsing()