Parse an integer "key":N from a flat JSON object. Returns def if absent. */
| 45 | |
| 46 | /* Parse an integer "key":N from a flat JSON object. Returns def if absent. */ |
| 47 | static int json_get_int(const char *json, const char *key, int dflt) { |
| 48 | if (!json) { |
| 49 | return dflt; |
| 50 | } |
| 51 | char pat[CBM_SZ_64]; |
| 52 | snprintf(pat, sizeof(pat), "\"%s\":", key); |
| 53 | const char *p = strstr(json, pat); |
| 54 | if (!p) { |
| 55 | return dflt; |
| 56 | } |
| 57 | p += strlen(pat); |
| 58 | while (*p == ' ' || *p == '\t') { |
| 59 | p++; |
| 60 | } |
| 61 | return (int)strtol(p, NULL, CBM_DECIMAL_BASE); |
| 62 | } |
| 63 | |
| 64 | /* Parse a boolean "key":true/false from a flat JSON object. */ |
| 65 | static bool json_get_bool(const char *json, const char *key) { |