Browse Source

Fixed code formatting

Sergey Lyubka 11 years ago
parent
commit
0404435f74
1 changed files with 18 additions and 19 deletions
  1. 18 19
      README.md

+ 18 - 19
README.md

@@ -16,32 +16,31 @@ JSON parser for C/C++
 # How to use it
 # How to use it
 
 
    1. Copy `frozen.c` and `frozen.h` to your project
    1. Copy `frozen.c` and `frozen.h` to your project
-   2. Add frozen.c to the list of source files
-   3. In a file that must do JSON parsing, add `#include "frozen.h"`
-      and call the API, like in an example below:
+   2. Add `frozen.c` to the list of source files
+   3. In a file that must do JSON parsing call the API like in an example below
 
 
 
 
-    #include <stdio.h>
-    #include "frozen.h"
+        #include <stdio.h>
+        #include "frozen.h"
 
 
-    int main(void) {
-      static const char *json = " { foo: 1, bar: 2 } ";
-      struct json_token tokens[10];
-      int code, size = sizeof(tokens) / sizeof(tokens[0]);
+        int main(void) {
+          static const char *json = " { foo: 1, bar: 2 } ";
+          struct json_token tokens[10];
+          int parsed_len, size = sizeof(tokens) / sizeof(tokens[0]);
 
 
-      code = parse_json(json, strlen(json), tokens, size);
-      if (code <= 0) {
-        printf("Error parsing [%s], error code: %d\n", json);
-      } else {
-        const struct json_token *tok = find_json_token(tokens, "bar");
-        printf("Value of bar is: [%.*s]\n", tok->len, tok->ptr);
-      }
+          parsed_len = parse_json(json, strlen(json), tokens, size);
 
 
-      return 0;
-    }
+          if (parsed_len > 0) {
+            const struct json_token *tok = find_json_token(tokens, "bar");
+            printf("Value of bar is: [%.*s]\n", tok->len, tok->ptr);
+          } else {
+            printf("Error parsing [%s], error code: %d\n", json, parsed_len);
+          }
 
 
+          return 0;
+        }
 
 
-# API
+# API documentation
 
 
     int parse_json(const char *json_string, int json_string_length,
     int parse_json(const char *json_string, int json_string_length,
                    struct json_token *tokens_array, int size_of_tokens_array);
                    struct json_token *tokens_array, int size_of_tokens_array);