-
Notifications
You must be signed in to change notification settings - Fork 778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does jsmn support parsing group with key, value pair. Example for parsing group with key, value pair #141
Comments
|
Thanks for checking. I made changes to simple.c example program in your repo. Here below is the JSON_STRING updatedwith a group with key, value pair: static const char *JSON_STRING = else if (jsoneq(JSON_STRING, &t[i], "plat_conf") == 0) { Here is my output:
As you can see above the parsing fails. Here is the complete simple.c, with my changes: /*
static const char *JSON_STRING = static int jsoneq(const char *json, jsmntok_t *tok, const char *s) { int main() {
} |
It will be great, if you can provide some code snippets, on what changes are needed to parse group with key, value pair in the modified simple.c that I had pasted previously. |
You're on the right track. In the for loop you added you now have to, for each token, see if it's
|
Thanks for your inputs. I tried your suggestion, but ran into issue. For example, since I have 2 rows for key-value pair, under the group plat_info, I was expecting, t[1+1].size will be 2. But I am getting 0 for t[1+1].size, so its NOT looping all the entries. And same thing even with the group array, which is existing code in the repo. Ideally, I would like to compare the key field, and then print the value. Can you provide some example code that can do above. Here is my modified simple.c, along with the output: #include <stdio.h> /*
static const char *JSON_STRING = static int jsoneq(const char *json, jsmntok_t *tok, const char *s) { int main() {
} OUTPUT:
|
it's supposed to be |
Can you let me know, if a group with key, value pair is supported.
For example, if I have a json file, that is read by my program, and lets say the contents of the json file is below:
{
"plat_conf": {
"ip_addr": "127.0.0.1",
"port_num": "4444"
}
}
The program simple.c, under example directory, has an example of a group that has an array of strings.
I tried to modify simple.c, to parse a group with key, value pair, and ran into issues.
Can you please let me know below:
The text was updated successfully, but these errors were encountered: