I've been trying to use the following code, taken from an example, I've had to change json_object_object_get(struct json_object *obj, const char *key) to json_object_get_ex(struct json_object *obj, const char *key, struct json_object **value)
I'm sorry I've already posted similar questions as I've been trying to find a way to parse json from a socket for days and I'm getting desperate, but I've done some more work and research and I think this is much close. The error I'm getting from compiling the below is:
server4.c: In function ‘main’: server4.c:62: error: dereferencing pointer to incomplete type server4.c:68: warning: assignment makes pointer from integer without a cast
struct json_object *jobj, *val_jobj, *value;
char const *val;
char buf[50];
fgets(buf, sizeof(buf), stdin);
printf("Input JSON : %s", buf);
char const *val;
*jobj = json_tokener_parse(buf);
if (is_error(jobj))
return (-1);
printf("Received JSON in String format : %s\n",
json_object_to_json_string(jobj));
//Get the value for the key "name"
val_jobj = json_object_object_get_ex(jobj, "name", &value);
printf("Extracted value for command : %s\n",
//Get the string from the value of the key "name"
val = json_object_get_string(val_jobj);
printf("String value returned : %s\n", val);
I can't see what is wrong and I don't fully understand how json-c works, I'm also more familiar with c++, though of course I use pointers there too. Either way, reading through some json parsers for c++, I've found them way easier to understand.
Thanks in advance