-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
[Feature Request] Lookup value via given key #79
Comments
These would just be wrappers around me also traversing the linked list to find the key that matches. If you went for multiple keys it'd be very inefficient to do it this way. Happy to accept a PR to add these helper functions if you think it is worth it though, we'll just have to document the worst case behaviour. |
I use this, the api is a bit different tho. struct json_value_s *root = json_parse(data, size);
struct json_object_element_s * const start = ((struct json_object_s *)root->payload)->start;
struct json_object_element_s *curr = start;
double width = 0;
if (json_object_get_double("width", start, &curr, &width) == 0) {
printf("width: %.1f\n", width);
}
curr = curr->next;
int size = 0;
if (json_object_get_int("size", start, &curr, &size) == 0) {
printf("size: %d\n", size);
}
curr = curr->next;
struct json_array_s *data;
if (json_object_get_array("data", start, &curr, &data) == 0) {
struct json_array_element_s *json_value = data->start;
for (size_t i = 0; i < layer_data->length; i++) {
printf("%d\n", atoi(json_value_as_number(json_value->value)->number));
json_value = json_value->next;
}
}
curr = curr->next;
... it traverses the list starting from it works great for me, if someone can point out a more convenient api, i would be glad to help, searching a json by key is a common operation, and worth the inclusion. |
Great work so far.
However one thing that would help tremendously is to have a (family of) utility function to look up values by a given key - right now I'd have to iterate through a linked list of the members of the json object, which makes the implemenation curve annoying. This has it's own performance implications ofc.
Parson has something like these:
The text was updated successfully, but these errors were encountered: