JE_NOT_JSON_CHR= -2, /* Character met not used in JSON. */ /* ASCII 00-08 for instance. */
JE_EOS= -3, /* Unexpected end of string. */
JE_SYN= -4, /* The next character breaks the JSON syntax. */
JE_STRING_CONST= -5, /* Character disallowed in string constant. */
JE_ESCAPING= -6, /* Error in the escaping. */
JE_DEPTH= -7, /* The limit on the JSON depth was overrun. */
JE_KILLED= -8, /* Killed during processing */
};
typedefstruct st_json_string_t
{ const uchar *c_str; /* Current position in JSON string */ const uchar *str_end; /* The end on the string. */
my_wc_t c_next; /* UNICODE of the last read character */ int c_next_len; /* character length of the last read character. */ int error; /* error code. */
CHARSET_INFO *cs; /* Character set of the JSON string. */
my_charset_conv_mb_wc wc; /* UNICODE conversion function. */ /* It's taken out of the cs just to speed calls. */
} json_string_t;
/* Path step types - actually bitmasks to let '&' or '|' operations. */ enum json_path_step_types
{
JSON_PATH_KEY_NULL=0,
JSON_PATH_KEY=1, /* Must be equal to JSON_VALUE_OBJECT. */
JSON_PATH_ARRAY=2, /* Must be equal to JSON_VALUE_ARRAY. */
JSON_PATH_KEY_OR_ARRAY=3,
JSON_PATH_WILD=4, /* Step like .* or [*] */
JSON_PATH_DOUBLE_WILD=8, /* Step like **.k or **[1] */
JSON_PATH_KEY_WILD= 1+4,
JSON_PATH_KEY_DOUBLEWILD= 1+8,
JSON_PATH_ARRAY_WILD= 2+4,
JSON_PATH_ARRAY_DOUBLEWILD= 2+8,
JSON_PATH_NEGATIVE_INDEX= 16,
JSON_PATH_ARRAY_RANGE= 32
};
typedefstruct st_json_path_step_t
{ enum json_path_step_types type; /* The type of the step - */ /* see json_path_step_types */ const uchar *key; /* Pointer to the beginning of the key. */ const uchar *key_end; /* Pointer to the end of the key. */ int n_item; /* Item number in an array. No meaning for the key step. */ int n_item_end; /* Last index of the range. */
} json_path_step_t;
typedefstruct st_json_path_t
{
json_string_t s; /* The string to be parsed. */
MEM_ROOT_DYNAMIC_ARRAY steps; /* Steps of the path. */ int last_step_idx;
int mode_strict; /* TRUE if the path specified as 'strict' */ enum json_path_step_types types_used; /* The '|' of all step's 'type'-s */
} json_path_t;
json_engine_tj_eng;// structure keeps parser's data json_scan_start(j_eng)// begin the parsing
do { // The parser has read next piece of JSON // and set fields of j_eng structure accordingly. // So let's see what we have: switch(j_eng.state) { caseJST_KEY: // Handle key name. See the json_read_keyname_chr() // Probably compare it with the keyname we're looking for caseJST_VALUE: // Handle value. It is either value of the key or an array item. // see the json_read_value() caseJST_OBJ_START: // parser found an object (the '{' in JSON) caseJST_OBJ_END: // parser found the end of the object (the '}' in JSON) caseJST_ARRAY_START: // parser found an array (the '[' in JSON) caseJST_ARRAY_END: // parser found the end of the array (the ']' in JSON)
}; }while(json_scan_next()==0);// parse next structure
if(j_eng.s.error)// we need to check why the loop ended. // Did we get to the end of JSON, or came upon error. { signal_error_in_JSON() }
/* These are JSON parser states that user can expect and handle. */ enum json_states {
JST_VALUE, /* value found */
JST_KEY, /* key found */
JST_OBJ_START, /* object */
JST_OBJ_END, /* object ended */
JST_ARRAY_START, /* array */
JST_ARRAY_END, /* array ended */
NR_JSON_USER_STATES
};
enum json_num_flags
{
JSON_NUM_NEG=1, /* Number is negative. */
JSON_NUM_FRAC_PART=2, /* The fractional part is not empty. */
JSON_NUM_EXP=4, /* The number has the 'e' part. */
};
typedefstruct st_json_engine_t
{
json_string_t s; /* String to parse. */ int sav_c_len; /* Length of the current character.
Can be more than 1 for multibyte charsets */
int state; /* The state of the parser. One of 'enum json_states'.
It tells us what construction of JSON we've just read. */
/* These values are only set after the json_read_value() call. */ enum json_value_types value_type; /* type of the value.*/ const uchar *value; /* Points to the value. */ const uchar *value_begin;/* Points to where the value starts in the JSON. */ int value_escaped; /* Flag telling if the string value has escaping.*/
uint num_flags; /* the details of the JSON_VALUE_NUMBER, is it negative, orifithasthefractionalpart.
See the enum json_num_flags. */
const uchar *value_end; /* Points to the next character after the value. */ int value_len; /* The length of the value. Does not count quotations for */ /* string constants. */ /* Keeps the stack of nested JSON structures. */
MEM_ROOT_DYNAMIC_ARRAY stack; int stack_p; /* The 'stack' pointer. */ volatileconst uint32_t *killed_ptr;
} json_engine_t;
int json_scan_start(json_engine_t *je,
CHARSET_INFO *i_cs, const uchar *str, const uchar *end); int json_scan_next(json_engine_t *j);
if(j_eng.state==JST_VALUE) { json_read_value(&j_eng); switch(j_eng.value_type) { caseJSON_VALUE_STRING: // get the string str=j_eng.value; str_length=j_eng.value_len; caseJSON_VALUE_NUMBER: // get the number ...etc }
*/ int json_read_value(json_engine_t *j);
int json_skip_array_and_count(json_engine_t *j, int* n_item);
/* ComparetwoJSONstringvaluessemantically,takingUnicodeescape sequencesintoaccount.Forexample,"A"and"\u0041"areconsideredequal. Returns0ifthestringsareequal,non-zerootherwise.
*/ int json_string_compare(CHARSET_INFO *cs, const uchar *str1, int len1, int escaped1, const uchar *str2, int len2, int escaped2);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.