I know that std::string cannot be null, but I can't figure out the problem here, let me explain. This is my function:
void HandleResponse(Mod::PlayerEntry player, std::string response)
So response usually has a json value, I parse it with nlohmann json:
auto value = json::parse(response);
In certain occasions, it gives "null", I debugged using:
std::cout << "response: " << response << ", value: " << value << std::endl;
// outputs: response: null, value: null
Now the problem is that I can't figure out how to compare if it's null, here's all the different checks I've tried:
if(response == "null"){}
if(response == ""){}
if(response.empty()){}
if(response == 0){}
if(response == std::string("null")){}
if(response.c_str() == "null"){}
if(response.c_str() == NULL){}
if(response.c_str() == '\0'){}
if(value == "null"){}
None of these have worked.
if (response.length() == 0)orif (!response.empty()).unsigned char **pk, then these are definedauto id = *(unsigned int *) (*pk + 40); auto data = *(std::string *) (*pk + 48);, thedatavariable is passed toHandleResponseasresponse.response? Does the json library not allow you to check if the value is null? Looking atnlohmannit looks likejson::parse()returns an object ofjson. Note this is not astd::string. Thejsonobject has a convenient type checker:value.is_null().