Stupid problem with booleans

superfisi
2012-02-17
2015-06-18
  • superfisi
    superfisi
    2012-02-17

    Hi there,

    it may sound stupid to you but I can't get boolan-inputs to work with cJSON, e.g. input like this…

    {"someInput":true}
    

    … at first I thought that cJSON treats booleans like integers, but the result is always "0".

    Can someone give me a hint?

    Thanks in advance!

     
  • Dave Gamble
    Dave Gamble
    2012-05-01

    For booleans, check the type. cJSON_False / cJSON_True. :)

    Dave.

     
  • In the readme file I found this json example:
    {
    "name": "Jack (\"Bee\") Nimble",
    "format": {
    "type": "rect",
    "width": 1920,
    "height": 1080,
    "interlace": false,
    "frame rate": 24
    }
    }
    if I'd like to parse a int field or a string field I use cJSON_GetObjectItem(json,"frame rate")->valueint or cJSON_GetObjectItem(json,"type")->valuestring.

    But how to parse bool value?

    Thanks!