#include#include int main() { Json::Value root; root["temperature"] = 23.5; float temp = root["temperature"].asFloat(); std::cout << "The temperature is " << temp << " degrees Celsius.\n"; return 0; }
#includeIn this example, we start with a JSON string that contains a temperature value of 23.5. We use a Json::Reader object to parse the string into a Json::Value object. Then, we use the asFloat method to extract the temperature value and store it in a float variable. We print out the value to the console using cout. The package library for this code is the C++ JSON library by Niels Lohmann.#include int main() { std::string json_data = "{ \"temperature\": 23.5 }"; Json::Value root; Json::Reader reader; bool success = reader.parse(json_data, root); if (success) { float temp = root["temperature"].asFloat(); std::cout << "The temperature is " << temp << " degrees Celsius.\n"; } return 0; }