nlohmann::basic_json::operator T() - renxiaobo27/json GitHub Wiki
template<typename T>
operator T() const;Implicitly converts a value of a JSON container.
None.
The return value is get<T>().
Amortized linear in the size of the JSON type.
std::std::logic_error if types are not compatible.
#include <json.hpp>
#include <vector>
#include <list>
#include <unordered_set>
#include <map>
#include <string>
int main()
{
nlohmann::json j1 = {1, 2, 3.2, 4.3, 5.4};
std::vector<float> v11 = j1;
std::list<int> v12 = j1;
std::unordered_set<float> v13 = j1;
nlohmann::json j2 = {{"one", 1}, {"two", 2}, {"three", 3}};
std::map<std::string, size_t> v21 = j2;
std::multimap<std::string, double> v22 = j2;
nlohmann::json j3 = "Hello, world";
std::string v31 = j3;
}-
get
explicit value conversion