Skip to content
Snippets Groups Projects
Commit 01f2ec83 authored by Arun Muthusamy's avatar Arun Muthusamy
Browse files

update function get_json_string_object_by_key

parent deecbab3
Branches
No related tags found
No related merge requests found
...@@ -52,38 +52,27 @@ struct blob_buf json_to_blob(struct json_object *response, struct blob_buf bb) ...@@ -52,38 +52,27 @@ struct blob_buf json_to_blob(struct json_object *response, struct blob_buf bb)
return bb; return bb;
} }
//free memory "return_object" struct json_object *get_json_string_object_by_key(json_object *json_obj, char *string)
struct json_object *json_parse_string(json_object *jsonContainer, char *string)
{ {
json_object_iter iterator; json_object_iter iterator;
json_object *return_object; json_object *string_object = NULL;
enum json_type type; enum json_type type;
int string_found = 0;
type = json_object_get_type(json_obj);
type = json_object_get_type(jsonContainer); if (type == json_type_object) {
if (type == json_type_object) { //search the key from the json object
json_object_object_foreachC(jsonContainer, iterator) { json_object_object_foreachC(json_obj, iterator) {
//prints the key.. printf("iteratorKey is :%s\n", iterator.key);
printf("iteratorKey is :%s\n", iterator.key); if (strcmp(string, (char *)iterator.key) == 0) {
if (strcmp(string, (char *)iterator.key) == 0) { string_object = json_object_object_get(json_obj,iterator.key);
return_object = json_object_object_get(jsonContainer,iterator.key); printf("Input string value: %s\n", (char *)json_object_get_string(iterator.val));
printf("Input string value: %s\n", (char *)json_object_get_string(iterator.val)); break;
string_found = 1; }
break; }
} }
} return string_object;
}
if (string_found)
return return_object;
else
goto string_not_found;
fail_calloc:
string_not_found:
return NULL;
} }
void xml_to_json(xmlNode *anode, json_object *jobj) void xml_to_json(xmlNode *anode, json_object *jobj)
{ {
xmlNodePtr cur_node = NULL; xmlNodePtr cur_node = NULL;
......
...@@ -82,5 +82,5 @@ int validate_puk_format(char *puk); ...@@ -82,5 +82,5 @@ int validate_puk_format(char *puk);
int validate_pin_format(char *pin); int validate_pin_format(char *pin);
int pin_status(struct blob_buf *bb, struct device *dev); int pin_status(struct blob_buf *bb, struct device *dev);
int check_response(struct json_object *response); int check_response(struct json_object *response);
struct json_object *json_parse_string(json_object *jsonContainer, char *string); struct json_object *get_json_string_object_by_key(json_object *json_obj, char *string);
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment