Created
September 27, 2012 12:51
-
-
Save deltheil/3793838 to your computer and use it in GitHub Desktop.
Checking parsing error with json-parser (https://github.com/udp/json-parser/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <json-parser/json.h> | |
int main(int argc, char *argv[]) { | |
char *str[] = { "{\"foo\": \"bar\"}" /* ok */, "{\"foo\": \"bar}" /* ko */ }; | |
for (int i = 0; i < 2; i++) { | |
json_settings settings; | |
memset(&settings, 0, sizeof(json_settings)); | |
char err[256]; | |
json_value *val = json_parse_ex(&settings, str[i], err); | |
if (val == 0) { | |
/* Parsing error */ | |
fprintf(stderr, "[KO]: %s\n", err); | |
} | |
else { | |
fprintf(stdout, "[OK]\n"); | |
json_value_free(val); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment