Skip to content

how to pass variable data to json in c #1567

Description

@naznaaa

Hi,
my sample code is given below

void hard_reset_warmer()
{    
   
	Get_Time();
	printf("%s\n", getString());
	char CreatedDate[64];
	strcpy(CreatedDate,getString());
	printf("%s\n", CreatedDate);
	printf("%s\n", CONFIG_FIRMWARE_VERSION);
	uint8_t mac_id[6];
    char MacID[17];
    esp_read_mac(mac_id, ESP_MAC_BT);
    sprintf(MacID,"%02x:%02x:%02x:%02x:%02x:%02x",mac_id[0],mac_id[1],mac_id[2],mac_id[3],mac_id[4],mac_id[5]);
    char Event[20];
	char FirmwareVersion[6];
	const char* const json_string = "{\"MacID\":\"%s\",\"Event\":\"HardReset\",\"CreatedDate\":\"%s\",\"FirmwareVersion\":\"%s\"}";
    cJSON * root = cJSON_Parse(json_string);  

    char *msgText = cJSON_Print(root);
	printf("%s\n", msgText);
}

here my MacID,CreatedDate and FirmwareVersion is varying then how can we create such a json
can you please help

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: enhancement/improvementsolution: invalidthe issue is not related to the librarystate: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updated

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions