Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A ArduinoJson
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Benoît Blanchon
  • ArduinoJson
  • Issues
  • #516
Closed
Open
Issue created May 31, 2017 by Administrator@rootContributor

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

Assignee
Assign to
Time tracking