always says Error parsing Json data. I don't know what is wrong exactly.?
//Opening json
FILE *fpj = fopen("data.json", "r");
if (fp == NULL) {
perror("Error opening file");
return 1;
}
fseek(fpj, 0, SEEK_END);
long json_file_size = ftell(fp);
rewind(fpj);
char *json_data = malloc(json_file_size + 1);
if (json_data == NULL) {
perror("Memory allocation error");
fclose(fpj);
return 1;
}
size_t bytes_read = fread(json_data, 1, json_file_size, fpj);
json_data[bytes_read] = '\0';
fclose(fpj);
struct json_object *root_object = json_tokener_parse(json_data);
if (root_object == NULL) {
fprintf(stderr, "Error parsing JSON data\n");
free(json_data);
return 1;
}
while (token != NULL) {
// Skip single-letter words
int know;
if (strlen(token) > 1) {
printf("%s: ", token);
scanf("%d", &know);
if(know==1){
char translation[100];
const char *key = token;
struct json_object *value = json_object_object_get(root_object, key);
if (value == NULL) {
fprintf(stderr, "Key '%s' not found in JSON data\n", key);
json_object_put(root_object);
free(json_data);
return 1;
}
const char *string_value = json_object_get_string(value);
printf("Value of key '%s': %s\n", key, string_value);
// Write the translation to the file
fprintf(translation_file, "%s - %s\n", token, translation);
}
}
token = strtok(NULL, " ");
}
json_object_put(root_object);
free(json_data);
print json_data before passing it to json_tokener_parse and show us the data, let's see json_tokener_parse
it is not possible to show that data into telegram the size of file 780KB, however I would send that as file if you want.
Обсуждают сегодня