Simple json lookup for a value by the key. Expects JSON object. Only scans the 'first level' of the object, not the nested structures. @param js [in] json object to search in @param js_end [in] end of json string @param key [in] key to search for @param key_end [in] - " - @param value_start [out] pointer into js (value or c
| 2157 | @retval JSV_NOTHING - no such key found. |
| 2158 | */ |
| 2159 | enum json_types json_get_object_key_int(json_engine_t *je, const char *js, |
| 2160 | const char *js_end, const char *key, |
| 2161 | const char **value, int *value_len) |
| 2162 | { |
| 2163 | const char *key_end= key + strlen(key); |
| 2164 | json_string_t key_name; |
| 2165 | int n_keys= 0; |
| 2166 | |
| 2167 | json_string_set_cs(&key_name, &my_charset_utf8mb4_bin); |
| 2168 | |
| 2169 | json_scan_start(je, &my_charset_utf8mb4_bin,(const uchar *) js, |
| 2170 | (const uchar *) js_end); |
| 2171 | |
| 2172 | if (json_read_value(je) || |
| 2173 | je->value_type != JSON_VALUE_OBJECT) |
| 2174 | goto err_return; |
| 2175 | |
| 2176 | while (!json_scan_next(je)) |
| 2177 | { |
| 2178 | switch (je->state) |
| 2179 | { |
| 2180 | case JST_KEY: |
| 2181 | n_keys++; |
| 2182 | json_string_set_str(&key_name, (const uchar *) key, |
| 2183 | (const uchar *) key_end); |
| 2184 | if (json_key_matches(je, &key_name)) |
| 2185 | return smart_read_value(je, value, value_len); |
| 2186 | |
| 2187 | if (json_skip_key(je)) |
| 2188 | goto err_return; |
| 2189 | |
| 2190 | break; |
| 2191 | |
| 2192 | case JST_OBJ_END: |
| 2193 | *value= (const char *) (je->s.c_str - je->sav_c_len); |
| 2194 | *value_len= n_keys; |
| 2195 | return JSV_NOTHING; |
| 2196 | } |
| 2197 | } |
| 2198 | |
| 2199 | err_return: |
| 2200 | return JSV_BAD_JSON; |
| 2201 | } |
| 2202 | |
| 2203 | enum json_types json_get_object_key(const char *js, const char *js_end, |
| 2204 | const char *key, const char **value, |
no test coverage detected