#include "json/json.h" #includeint main() { Json::Value obj; obj["num"] = 3.14159; double num = obj["num"].asDouble(); std::cout << "Number value: " << num << std::endl; return 0; }
#include "json/json.h" #includeIn this example, we create a JSON string that contains a single key-value pair, and parse it into a JSON object using the Json::Reader class. We then use the asDouble method to retrieve the double value of the "num" key and store it in the num variable. Finally, we print out the value of num. The cpp json library used in these examples is the JsonCpp library.int main() { std::string jsonStr = "{\"num\": 2.71828}"; Json::Value obj; Json::Reader reader; reader.parse(jsonStr, obj); double num = obj["num"].asDouble(); std::cout << "Number value: " << num << std::endl; return 0; }