I am trying to send a JSON from C++ code to a REST service running on Java. I am using Visaul Studio 2019, nlohmann/json library to serialize my objects and libcurl to make the HTTP request.
I have an the following object I want to serialize:
typedef struct{
int ordinal;
std::string detail;
Level level;
} LogType
static const LogType ONLINE = {0, "Çevrimiçi", Level::INFO};
I use this LogType to fill in some members of AliveLog(Very much similar to Java enums). And I use the following to serialize it:
std::string AliveLog::getJSON(){
json j = json{
{"createdAt", createdAt},
{"id", id},
{"message", message},
{"detail", detail},
{"deviceId", deviceId},
{"type", type.ordinal},
{"level", level}
};
return j.dump(-1, ' ', false, json::error_handler_t::replace);
}
When I call this function I get bunch of question marks and ½'s where "Çevrimdışı" should be.
Also my REST service throws an exception JSON parse error: Invalid UTF-8 middle byte 0xdd;
I tried setting /utf8 and /validate-charset for compiler command line options but no avail.
If I just use j.dump() with no argument it throws an exception saying "type_error.316 if a string stored inside the JSON value is not UTF-8 encoded". In my text editor I have "Auto-detect UTF-8 encoding without signature" selected.
This same piece of code work fine written in Java, I am trying to make a C++ version of it.
edit: Added more information regarding the LogType and AliveLog