X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fjsmn%2Fexample%2Fjsondump.c;h=b7d25cb0c677c92f516afeb55a2f43786d26153d;hb=acc96b5371d3d51633b9175609b0ce030a3d75db;hp=e0f998589c08bab88cf3f6fb474cec3fa23a5756;hpb=57aa59c0ea066dd3df8321d29871f6c9303ecf49;p=16.git diff --git a/src/lib/jsmn/example/jsondump.c b/src/lib/jsmn/example/jsondump.c index e0f99858..b7d25cb0 100644 --- a/src/lib/jsmn/example/jsondump.c +++ b/src/lib/jsmn/example/jsondump.c @@ -8,6 +8,13 @@ * An example of reading JSON from stdin and printing its content to stdout. * The output looks like YAML, but I'm not sure if it's really compatible. */ +static int jsoneq(const char *json, jsmntok_t *tok, const char *s) { + if (tok->type == JSMN_STRING && (int) strlen(s) == tok->end - tok->start && + strncmp(json + tok->start, s, tok->end - tok->start) == 0) { + return 0; + } + return -1; +} static int dump(const char *js, jsmntok_t *t, size_t count, int indent) { int i, j, k; @@ -18,6 +25,11 @@ static int dump(const char *js, jsmntok_t *t, size_t count, int indent) { printf("%.*s", t->end - t->start, js+t->start); return 1; } else if (t->type == JSMN_STRING) { + if(jsoneq(js, t, "data") == 0 ) + { +// printf("[[[[%d|%d]]]]\n", &(t+1)->size, (t+1)->size); + printf("\n%.*s[xx[%d|%d]xx]\n", (t+1)->end - (t+1)->start, js+(t+1)->start, &(t+1)->size, (t+1)->size); + } printf("'%.*s'", t->end - t->start, js+t->start); return 1; } else if (t->type == JSMN_OBJECT) { @@ -50,7 +62,7 @@ int main() { int eof_expected = 0; char *js = NULL; size_t jslen = 0; - char buf[BUFSIZ-256]; + char buf[BUFSIZ]; jsmn_parser p; jsmntok_t *tok;