From 26193d39c2d17bf184b691ebfa406b5b9782577a Mon Sep 17 00:00:00 2001 From: "Serge A. Zaitsev" Date: Fri, 19 Dec 2014 01:40:26 +0200 Subject: [PATCH] updated README --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a282407..353af94 100644 --- a/README.md +++ b/README.md @@ -126,19 +126,21 @@ to simplify string extraction from JSON data. All job is done by `jsmn_parser` object. You can initialize a new parser using: - struct jsmn_parser parser; + jsmn_parser parser; jsmntok_t tokens[10]; + jsmn_init(&parser); + // js - pointer to JSON string // tokens - an array of tokens available // 10 - number of tokens available - jsmn_init_parser(&parser, js, tokens, 10); - -This will create a parser, that can parse up to 10 JSON tokens from `js` string. + jsmn_parse(&parser, js, tokens, 10); -Later, you can use `jsmn_parse(&parser)` function to process JSON string with the parser. +This will create a parser, and then it tries to parse up to 10 JSON tokens from +the `js` string. -A non-negative value is the number of tokens actually used by the parser. +A non-negative reutrn value of `jsmn_parse` is the number of tokens actually +used by the parser. Passing NULL instead of the tokens array would not store parsing results, but instead the function will return the value of tokens needed to parse the given string. This can be useful if you don't know yet how many tokens to allocate.