How to convert boolean (True/False) to a float value
Created by: ghost
Dear author I am having a problem about converting a boolean value in JSON object to a float value. Here is my code
float getData(const char* payload){
StaticJsonBuffer<MQTT_MAX_PAYLOAD_SIZE> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(payload);
if (!root.success()) {
Serial.println("parseMsg() failed");
return;
}
if (root["data0"] == true){
return 1;
}else if(root["data0"] == false){
return 0;
}else{
return root["data0"];
};
}
I test this code and saw that:
- When i send a true/false value, the return value is 1/0 successfully
- However, when i send a float value, the return is always equal to 1.
Can you help me ? Thank you so much