Код: Выделить всё
void test_func() {
static const std::string map[] = {
"test1",
"test2",
};
nlohmann::json j;
j["state"] = map[state]; // 'state' is an index or variable representing the state
j["hsi"] = 1;
// Calculate current timestamp in milliseconds
std::chrono::milliseconds ms = std::chrono::duration_cast(
std::chrono::system_clock::now().time_since_epoch());
std::int64_t count = static_cast(ms.count());
j["timestamp"] = count;
// Sending the JSON payload
send_message(j.dump());
}
void send_message(const std::string& msg) {
void* payload = static_cast(const_cast(msg.c_str()));
// Here, 'payload' is sent out but it includes unreadable characters at the end
}
Код: Выделить всё
{"state":"test1","hsi":1,"timestamp":1721209944160}áC
Почему это может происходить? Будем очень признательны за любые идеи и предложения.
Подробнее здесь: https://stackoverflow.com/questions/787 ... conversion