Skip to content
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

how to pass variable data to json in c #1567

Closed
naznaaa opened this issue Apr 15, 2019 · 2 comments
Closed

how to pass variable data to json in c #1567

naznaaa opened this issue Apr 15, 2019 · 2 comments
Labels
kind: enhancement/improvement solution: invalid the issue is not related to the library state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated

Comments

@naznaaa
Copy link

naznaaa commented Apr 15, 2019

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

@nlohmann
Copy link
Owner

This issue may be long to https://github.com/DaveGamble/cJSON - this repository is for "JSON for Modern C++".

@stale
Copy link

stale bot commented May 15, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label May 15, 2019
@stale stale bot closed this as completed May 22, 2019
@nlohmann nlohmann added the solution: invalid the issue is not related to the library label Jun 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement/improvement solution: invalid the issue is not related to the library state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated
Projects
None yet
Development

No branches or pull requests

2 participants