Skip to content

auto iterator returned by find to handle value depending if is string or numeric. #2032

Closed
@Alphadan28

Description

I want to make a function which finds a key by name in a json object it works fine when the value is double, but if the value comes as "130.34" it fails, what i need is a way to determine its type if is coming as string then to convert it to double.

the values may come as directly double or as double but in a string ex. "130.34"

double jfind(json jdata, char* keyName){
     auto keytofind = jdata.find(keyName);

// Check if  *keytofind is string or numeric ????? how to do it???

     if(keytofind != jdata.end()){
        return *keytofind;
     }else{
        return 0;
     }
}

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions